-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Forbid direct access to static members on traits #4829
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
Usages found in open-source projects:
|
Heads up @z-song on the use of the trait member |
T::$foo = 42; | ||
var_dump(T::$foo); |
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.
These 2 lines should be in their own try/catch block, otherwise the case covered by the 2nd line would not be tested.
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 looks sensible - not sure whether there are real-world necessary use-cases for it, but they can be replaced via abstract class using the trait, I suppose.
I think, it's better to pass this change through RFC process. |
I think an RFC for 8 makes sense |
@nikic Do you still want to pursue this RFC for PHP 8.0? Or is it not that important to have in PHP 8.0? |
A deprecation for this is part of https://wiki.php.net/rfc/deprecations_php_8_1. Closing this outright removal. |
This forbids directly accessing static properties and static methods on traits. Trait members in general can only be used through the class in which the trait was used, but due to an implementation oversight access to static members was still allowed. This change remedies this.