-
Notifications
You must be signed in to change notification settings - Fork 82
Allow dynamic properties (e.g. endLineno) without deprecation notice in ast\Node #217
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
@@ -1518,6 +1522,10 @@ PHP_MINIT_FUNCTION(ast) { | |||
ast_declare_property(ast_node_ce, AST_STR(str_flags), &zv_null); | |||
ast_declare_property(ast_node_ce, AST_STR(str_lineno), &zv_null); | |||
ast_declare_property(ast_node_ce, AST_STR(str_children), &zv_null); | |||
#ifdef ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES | |||
zend_add_class_attribute(ast_node_ce, zend_ce_allow_dynamic_properties->name, 0); | |||
ast_node_ce->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES; |
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.
Setting the flag explicitly should not be necessary.
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 tried removing the line. Deprecated: Creation of dynamic property ast\Node::$undeclaredDynamic is deprecated in /home/tyson/programming/php-ast/tests/php82_metadata.php on line 18
is the result.
This is the same as what https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions.c does
at the time of writing:
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.
Ah yes, looks like the callback doesn't get called on interned classes for some reason.
…in ast\Node (But use the default deprecation behavior for ast\Metadata) 1. php-ast itself sets the dynamic property on endLineno right now, causing deprecation notices in PHP 8.2. Because all declaration types are associative arrays(not lists), a future AST version number may add this as a property of $node->children instead to avoid this notice. 2. WeakMap is only available in PHP 8.0+ (and WeakReference 7.4), but https://github.com/phan/phan targets PHP 7.2+. 3. Because some nodes make `$node->children` a list, applications such as Phan using php-ast can't associate string keys with that. (e.g. to mark nodes that were already processed in a certain step) https://github.com/nikic/php-parser solves that by adding `attributes`, `setAttribute`, `getAttribute`, etc. separately from children, but php-ast currently doesn't have an attributes node. That may be worth it in a future release. 4. When processing a large number of ast nodes in a large number of files, the deprecation notices have a noticeable performance impact, even when suppressed. Related to nikic#214
7001c93
to
d246ddd
Compare
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.
Fine by me, allowing custom node extensions seems like a pragmatic choice.
Make it possible to test with php 8.2 without deprecation notes for endLineno, etc. See nikic#217 Also, document how to properly update cache slot numbers if new properties are added to ast\Node in the future.
* Update php versions tested in CI PHP '8.1' isn't published yet on docker hub. Start testing with php 8.1 in appveyor * Prepare for a 1.0.15 release Make it possible to test with php 8.2 without deprecation notes for endLineno, etc. See #217 Also, document how to properly update cache slot numbers if new properties are added to ast\Node in the future.
(But use the default deprecation behavior for ast\Metadata)
php-ast itself sets the dynamic property on endLineno right now,
causing deprecation notices in PHP 8.2.
Because all declaration types are associative arrays(not lists),
a future AST version number may add this as a property of
$node->children instead to avoid this notice.
WeakMap is only available in PHP 8.0+ (and WeakReference 7.4),
but https://github.com/phan/phan supports PHP 7.2+.
Having a Phan version (or external plugins) that can work (and be fast) with a wider range of php versions is useful for organizations trying to detect uses of undeclared properties that need to migrate.
Because some nodes make
$node->children
a list,applications such as Phan using php-ast can't associate string keys
with that.
(e.g. to mark nodes that were already processed in a certain step)
https://github.com/nikic/php-parser solves that by adding
attributes
,setAttribute
,getAttribute
, etc. separately fromchildren, but php-ast currently doesn't currently have an attributes node.
That may be useful to add (and to remove the AllowsDynamicProperty annotation in an incompatible php-ast major release)
That may be worth it in a future release.
When processing a large number of ast nodes in a large number of
files, the deprecation notices have a noticeable performance impact,
even when suppressed.
Related to #214
Phan has a lot of uses of dynamic properties - e.g.
?:
syntax, trailing commas).