Skip to content

zend_ast: Wrap class names in parens during export when they are an expression#22389

Open
TimWolla wants to merge 1 commit into
php:masterfrom
TimWolla:zend-ast-export-class-name-expression
Open

zend_ast: Wrap class names in parens during export when they are an expression#22389
TimWolla wants to merge 1 commit into
php:masterfrom
TimWolla:zend-ast-export-class-name-expression

Conversation

@TimWolla

Copy link
Copy Markdown
Member

Fixes #22387.

@TimWolla TimWolla requested a review from iliaal June 21, 2026 20:07
@TimWolla TimWolla requested a review from bukka as a code owner June 21, 2026 20:07
@TimWolla TimWolla force-pushed the zend-ast-export-class-name-expression branch from add205b to 9c7592b Compare June 21, 2026 20:34
@TimWolla TimWolla requested a review from iluuu1994 June 21, 2026 20:35
@iliaal

iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

X::class (ZEND_AST_CLASS_NAME) still goes through zend_ast_export_ns_name(), so (bar)::class exports as bar::class, which re-parses to the string "bar" rather than (bar)::class. Same case as the (bar)::m() / (bar)::$p / (bar)::C ones already covered. Switching that branch to zend_ast_export_ns_name_or_expression() fixes it, and it's worth a (bar)::class line in the test.

@TimWolla TimWolla force-pushed the zend-ast-export-class-name-expression branch from 9c7592b to 6d478dd Compare June 21, 2026 21:41
@TimWolla

Copy link
Copy Markdown
Member Author

I had seen that and then during testing it complained about ::class not being legal on a string (since I was testing with a string constant) and then disregard that as a case that cannot happen in practice. Of course AST printing also needs to work with runtime errors, and constants can contain objects.

Now fixed, thanks.

@iliaal iliaal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Zend/zend_ast.c
zend_ast *method_ast = ast->child[1];

/* see zend_compile_parent_property_hook_call() */
bool parent_hook = !(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to a function. That also avoids the comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AST pretty-printing drops meaningful parentheses around RHS of instanceof

3 participants