Skip to content

Commit d8d1cb4

Browse files
authored
zend_ast: Print placeholder value when printing ZEND_AST_OP_ARRAY (#17405)
As per the discussion in GH-17120, we are printing a placeholder value only. The commit history of that PR also includes alternative implementations, should a different decision be desirable. Fixes GH-17096 Closes GH-17120
1 parent 8d79ed6 commit d8d1cb4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
AST printing for closures in attributes at runtime
3+
--FILE--
4+
<?php
5+
6+
#[Attr(static function ($foo) {
7+
echo $foo;
8+
})]
9+
function foo() { }
10+
11+
$r = new ReflectionFunction('foo');
12+
foreach ($r->getAttributes() as $attribute) {
13+
echo $attribute;
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Attribute [ Attr ] {
19+
- Arguments [1] {
20+
Argument #0 [ Closure({closure:foo():3}) ]
21+
}
22+
}

Zend/zend_ast.c

+5
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,11 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
18851885
smart_str_appendl(str, ZSTR_VAL(name), ZSTR_LEN(name));
18861886
break;
18871887
}
1888+
case ZEND_AST_OP_ARRAY:
1889+
smart_str_appends(str, "Closure(");
1890+
smart_str_append(str, zend_ast_get_op_array(ast)->op_array->function_name);
1891+
smart_str_appends(str, ")");
1892+
break;
18881893
case ZEND_AST_CONSTANT_CLASS:
18891894
smart_str_appendl(str, "__CLASS__", sizeof("__CLASS__")-1);
18901895
break;

0 commit comments

Comments
 (0)