-
Notifications
You must be signed in to change notification settings - Fork 82
Support PHP 8.4 property hooks in AST version 110 #241
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
Add 'hooks' child of type `AST_PROPERTY_HOOK` to `AST_PROP_ELEM` and `AST_PARAM` (constructor property promotion). Add test of `new X()->propName` Fixes nikic#240
d459695
to
35ed2cc
Compare
ast.c
Outdated
@@ -1037,6 +1071,11 @@ static void ast_to_zval(zval *zv, zend_ast *ast, ast_state_info_t *state) { | |||
// This is an undeclared dynamic property and has no cache slot. | |||
ast_update_property_long(zv, AST_STR(str_endLineno), decl->end_lineno); | |||
|
|||
#if PHP_VERSION_ID >= 80400 | |||
if (kind == ZEND_AST_CLOSURE || kind == ZEND_AST_ARROW_FUNC) { | |||
ZVAL_STR(&tmp_zv, AST_STR(str_bracketed_closure)); |
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.
What's this change for?
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.
It's because of https://github.com/php/php-src/pull/13550/files#diff-3e6742a9069b5717cf961c9d6b2aefbd1c730869d8a58123b1b5f3bc3e9082fc - php 8.4-dev has the name of closures be null instead of the old literal string {closure}
.
This affects unit tests, but shouldn't really affect phan.
This could probably be extended to be consistently null in versions 110+ of php-ast.
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.
Or have the field be omitted entirely for closures and arrow functions.
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.
Probably omitting it entirely would be best. But we can leave that for a followup.
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.
LGTM
README.md
Outdated
AST_PROP_GROUP: type, props, attributes // version 70+ | ||
AST_PROPERTY_HOOK: name, docComment, params, stmts, returnType, attributes // version 110+ |
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.
Drop returnType from here?
ast.c
Outdated
@@ -1037,6 +1071,11 @@ static void ast_to_zval(zval *zv, zend_ast *ast, ast_state_info_t *state) { | |||
// This is an undeclared dynamic property and has no cache slot. | |||
ast_update_property_long(zv, AST_STR(str_endLineno), decl->end_lineno); | |||
|
|||
#if PHP_VERSION_ID >= 80400 | |||
if (kind == ZEND_AST_CLOSURE || kind == ZEND_AST_ARROW_FUNC) { | |||
ZVAL_STR(&tmp_zv, AST_STR(str_bracketed_closure)); |
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.
Probably omitting it entirely would be best. But we can leave that for a followup.
Add 'hooks' child of type
AST_PROPERTY_HOOK
toAST_PROP_ELEM
andAST_PARAM
(constructor property promotion).Fixes #240