-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Stdlib\Options: Misc enhancements #6884
Stdlib\Options: Misc enhancements #6884
Conversation
Pittiplatsch
commented
Nov 17, 2014
- Minor performance tweak - consolidate calls to method_exists
- Replace method_exists with more reliable is_callable
- CS fixes
* Replace method_exists with more reliable is_callable * CS fixes
Behaviour is different, |
throw new Exception\BadMethodCallException( | ||
'The option "' . $key . '" does not ' | ||
. 'have a callable "' . $setter . '" setter method ' | ||
. 'which must be defined' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZF2 normally uses sprintf()
for exception messages.
throw new Exception\BadMethodCallException(sprintf(
'The option "%s" does not have a callable '
. '"%s" setter method which must be defined',
$key,
$setter
));
|
When someone uses <?php
namespace MyNamespace;
use Zend\Stdlib\AbstractOptions;
class CustomOptions extends AbstractOptions
{
public function __call($methodName, $arguments)
{
}
}
$options = new CustomOptions();
var_dump(is_callable(array($options, 'getFoo'))); // true
var_dump(method_exists($options, 'getFoo')); // false |
Uh, you're right - didn't see that :-( Don't know though if this (undoubtly existing) BC is relevant. |
); | ||
} elseif (!$this->__strictMode__ && !method_exists($this, $setter)) { | ||
return; | ||
if (!is_callable(array($this, $setter))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can swap this conditional by making the setter call if is_callable()
, and handling exceptions later on. Simplifies the method by a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if a static local cache would bring any benefit here, or if it's a total overkill.
@Ocramius I think the milestone should be 2.4.0 because |
Requires a documentation change: using And yes, moved to |
@Pittiplatsch can you check the new behavior with a test that throws an exception with |
Will think about it tomorrow. |
Tests added, but one of them fails although IMO it should succeed. |
Played with your gist a bit: http://3v4l.org/mQ57X May be related with https://bugs.php.net/bug.php?id=29210 and https://bugs.php.net/bug.php?id=33277, not sure tho. It seems to me that This makes sense though, as it is indeed not possible to call |
IMO |
Correct. |
"Again what learned" ;-) |
@Pittiplatsch right: I think we have to leave the |
Unit tests are passing now. BC break: IMO this isn't necessary, because switching from
|
@Pittiplatsch it still needs documentation for these edge-cases (documented limitation) |
…t the correct point in code execution
@Pittiplatsch merged into |
…ng exception expectations at the correct point in code execution
…toptions-performance-tweaks' into develop Close zendframework/zendframework#6884