Skip to content

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

Merged
merged 4 commits into from
Aug 10, 2024

Conversation

TysonAndre
Copy link
Collaborator

Add 'hooks' child of type AST_PROPERTY_HOOK to AST_PROP_ELEM and AST_PARAM (constructor property promotion).

Fixes #240

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
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));
Copy link
Owner

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Owner

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.

Copy link
Owner

@nikic nikic left a 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+
Copy link
Owner

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));
Copy link
Owner

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.

@TysonAndre TysonAndre merged commit 1fc2c3a into nikic:master Aug 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails to compile with php 8.4.0 alpha 3 or newer
2 participants