-
Notifications
You must be signed in to change notification settings - Fork 81
Description
NOTE: In my own use case (https://github.com/phan/phan), I use tolerant-php-parser as part of a polyfill that I convert to ast\Node
and I end up associating dynamic information with ast\Node
instances, so I don't personally need this (they all work fine in php 8.2), but other projects might.
I'm bringing this up so that it can be considered before projects are affected
- E.g. for caching inferred types, or caching expensive operations such as whether a given node has been processed in a given way, etc
PHP 8.2 deprecates dynamic properties by default and PHP 9.0 will remove support by default without the AllowDynamicProperties annotation. https://wiki.php.net/rfc/deprecate_dynamic_properties
- Projects using tolerant-php-parser can use WeakMap as a substitute for dynamic properties on Microsoft\PhpParser\Node (though it had worse performance until the latest php minor releases). For php 7.4 and older, https://github.com/TysonAndre/pecl-weakreference_bc is an option I'd created (expecting projects to benefit from this for 8.2 in general) but has low adoption. More conveniently than using a PECL, hybrid approaches such as using dynamic properties/SplObjectStorage in older versions and WeakMaps in newer versions might be possible.
The approaches used in similar libraries:
- https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/Node.php uses a different approach, which is to explicitly declare an attributes array internally for each node, to discourage dynamic properties
- https://github.com/nikic/php-ast/blob/master/ast.stub.php uses
#[\AllowDynamicProperties]
(and Phan makes use of that)
Options:
-
Add
#[\AllowDynamicProperties]
to classes in the current release line, so that php 8.1 and 8.2 will behave the same way, and applications can stay as isIn 8.x, the memory usage is the same with/without this property
-
Do nothing, let projects implement alternate solutions when they fix 8.2 deprecations or support 9.0
-
Add attributes array nodes so that projects can switch to that (increase memory slightly per node by 16 bytes for a zval when empty)
This is out of scope of what I'd prefer in the 0.1.2 release