-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #68475 - Support $callable() syntax for all callable strings. #1264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Using the $callable() syntax when used with a string of the form 'Class::method' would error as an undefined function, even if the string passed is_callable() or the callable type-hint. The fix adds support for the $callable() syntax for any string accepted by is_callable() or the callable type-hint.
|
||
called_scope = zend_fetch_class_by_name(lcname, NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION); | ||
if (UNEXPECTED(called_scope == NULL)) { | ||
zend_string_release(lcname); |
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.
I think a proper ERROR should also be triggered here.
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.
This does trigger a 'Class not found' error in the same way passing an array ['ClassName', 'methodName']
behaves if ClassName
does not exist.
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.
hmm, then okey, I thought a similar error "call to undefined" should be triggered. but fine, let keep them consistent.. thanks
Oops, forgot to add the deprecated notice to the test expected output. Fixed now. |
There's a failed unittest in there as well =) |
It's my own unit test that is failing, but it passes when I build it on my computer. It seems the build on travis actually does call the non-static method when I try to call it statically, rather than throw an The code that checks if the method can be called statically is copied directly from the portion that handles calls based on arrays like
It seems the code to check if the method can be called statically is saying it can be called statically. I tried the array syntax and it fails in the same way, so maybe there's a bug in both the code I added and the code that handles array style callbacks. |
Would be great to have tests with: $callback($arg, $arg);
$callback(...$args); |
I reduced the scope of the unit test I added with this pull, since it seemed to find a separate issue that needs to be addressed. It seems that the @marcioAlmada Sure, I can add some more tests with arguments. |
Thanks @trowski for fixing this callable paradox, I hope your PR gets merged real soon and that we don't ever have to use |
I added a few tests with arguments to the unit test, but oddly it didn't trigger a travis build. Can someone manually trigger the build. The tests are simple and passed on my local build. Thoughts on getting this merged? |
@trowski sometimes travis refuses to start builds for pull requests. Try to |
@marcioAlmada Thank you, that worked. |
No test failing for me on my env. @laruence : more things to add ? |
@jpauli No. :) |
Merged |
Quick question, will this fix apply to all PHP version, or only PHP7? |
This is merged against PHP7 |
Since this can be considered as a bug fix, do you think there's a chance that PHP5.4 - 5.6 will also be fixed? The type |
No sorry. This is controversal, we prefer not changing PHP5 VM stability and performance, but bet on PHP7. |
Ok I understand. Thanks for your reply. |
The
$callable()
syntax when used with a string of the form'Class::method'
would error as an undefined function, even if the string returnedtrue
fromis_callable()
or thecallable
type-hint. This fix adds support for the$callable()
syntax for any string accepted byis_callable()
or thecallable
type-hint.Prior output:
After patch: