-
Notifications
You must be signed in to change notification settings - Fork 715
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
ArrayObject - undocumented AllowDynamicProperties? #2484
Comments
ArrayObject implements an internal equivalent to the __get/set/etc. methods. In other words, property access doesn't go through the normal paths that are affected by this RFC. This will also apply to other classes that override property access behaviors, such as SimpleXMLElement. Not sure if there's anything that needs to be added to the docs about this: it's not really a userland concern exactly how ArrayObject or SimpleXMLElement work as long as the Regarding phrasing in the RFC: it was aimed more towards userland classes than literally all classes within PHP. It would be more accurate to say that the default property handlers were updated to disallow dynamic properties, and thus that classes using those handlers are the ones that will be affected by the new rules. edit: For PHPStan, short of a whitelist of classes that support dynamic properties (if not otherwise known) it could be difficult to support rules on built-in classes without some number of false positives. But applying rules to userland classes, at least, should be safe. |
These are the relevant handlers that are overwritten: You could search for these in the PHP source code to understand what classes have special behavior. You might also want to search for |
Description
The following code:
Resulted in this output:
But I expected this output instead:
The PHP RFC "Deprecate dynamic properties" says that only
stdClass
, classes with magic __get/__set methods, and classes marked as#[AllowDynamicProperties]
are allowed to have dynamic properties.But ArrayObject is none of those:
So what are the rules about dynamic properties? Are there any other cases where they are allowed that I'm unaware of?
Please understand I'm asking from the point of a static analyser developer, to be able to describe these cases. I get it it's useful to have ArrayObject to allow them, but I need the rules to describe this behaviour.
Thank you.
PHP Version
PHP 8.2
Operating System
No response
The text was updated successfully, but these errors were encountered: