Skip to content

zend_ast: Print placeholder value when printing ZEND_AST_OP_ARRAY #17405

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 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Zend/tests/closure_const_expr/attributes_ast_printing_runtime.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
AST printing for closures in attributes at runtime
--FILE--
<?php

#[Attr(static function ($foo) {
echo $foo;
})]
function foo() { }

$r = new ReflectionFunction('foo');
foreach ($r->getAttributes() as $attribute) {
echo $attribute;
}

?>
--EXPECT--
Attribute [ Attr ] {
- Arguments [1] {
Argument #0 [ Closure({closure:foo():3}) ]
}
}
5 changes: 5 additions & 0 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,11 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appendl(str, ZSTR_VAL(name), ZSTR_LEN(name));
break;
}
case ZEND_AST_OP_ARRAY:
smart_str_appends(str, "Closure(");
Copy link
Member

Choose a reason for hiding this comment

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

The format looks a bit non-standard, but I don't have a better suggestion.

smart_str_append(str, zend_ast_get_op_array(ast)->op_array->function_name);
smart_str_appends(str, ")");
break;
case ZEND_AST_CONSTANT_CLASS:
smart_str_appendl(str, "__CLASS__", sizeof("__CLASS__")-1);
break;
Expand Down
Loading