-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
PHP 7.0: Returning by reference from magic methods, e.g. __call()
, __callStatic()
#1675
Comments
@MarkMaldaba I agree there is a change (which may or may not be detected in PHPCompatibility, I need to check), but the change has nothing to do with |
Hi @jrfnl. No, your fiddle is not doing the same thing and I would expect things to work the same across PHP versions if you are not returning by reference. The point is that PHP < 7 does not allow you to return values by reference from However, once the ability to return by reference was added, the assign by reference is acceptable and (a) no longer throws a notice; and (b) correctly holds a reference to the static class property, meaning changes made to the variable in the outer scope affect the class variable in the inner scope. It is the second of these that is the more significant backwards-compatibility issue, and the reason I am flagging this. Here is another fiddle which demonstrates the difference between |
@MarkMaldaba It would be helpful to find the exact change in PHP, either the commit which made this change or any RFC/UPGRADING reference related to it. I want to properly understand what was exactly has changed to be able to evaluate whether this is sniffable or not and what exactly should be sniffed for. |
I'm not completely sure, but this looks like the commit where it was changed: php/php-src@5e8133f This is a change to how |
__call()
, __callStatic()
__call()
, __callStatic()
I've just come across an interesting thing that I can't find any documentation for, but which is a clear difference in implementation between PHP versions.
It appears that the magic methods (e.g.
__call()
,__callStatic()
, etc.) allow you to return values by reference as of PHP 7. However, this doesn't work in PHP 5.Example (3v4l.org)
PHPCompatibility should warn if magic methods are prefixed by
&
when testing against PHP < 7.0.The text was updated successfully, but these errors were encountered: