Skip to content

Commit cd7fcc1

Browse files
committed
zend_ast: Add AST printing support for clone property list
1 parent 4e5e58b commit cd7fcc1

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

Zend/tests/clone/ast.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Ast Printing
3+
--FILE--
4+
<?php
5+
6+
$x = new stdClass();
7+
8+
9+
try {
10+
assert(false && $y = clone $x);
11+
} catch (Error $e) {
12+
echo $e->getMessage(), PHP_EOL;
13+
}
14+
15+
try {
16+
assert(false && $y = clone($x));
17+
} catch (Error $e) {
18+
echo $e->getMessage(), PHP_EOL;
19+
}
20+
21+
try {
22+
assert(false && $y = clone($x, foo: $foo, bar: $bar));
23+
} catch (Error $e) {
24+
echo $e->getMessage(), PHP_EOL;
25+
}
26+
27+
try {
28+
assert(false && $y = clone($x, ...$array));
29+
} catch (Error $e) {
30+
echo $e->getMessage(), PHP_EOL;
31+
}
32+
33+
try {
34+
assert(false && $y = clone($x, ...[
35+
"foo" => $foo,
36+
"bar" => $bar,
37+
]));
38+
} catch (Error $e) {
39+
echo $e->getMessage(), PHP_EOL;
40+
}
41+
42+
43+
?>
44+
--EXPECT--
45+
assert(false && ($y = clone($x)))
46+
assert(false && ($y = clone($x)))
47+
assert(false && ($y = clone($x, foo: $foo, bar: $bar)))
48+
assert(false && ($y = clone($x, ...$array)))
49+
assert(false && ($y = clone($x, ...['foo' => $foo, 'bar' => $bar])))

Zend/zend_ast.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,15 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
22852285
smart_str_appendc(str, '`');
22862286
break;
22872287
case ZEND_AST_CLONE:
2288-
PREFIX_OP("clone ", 270, 271);
2288+
smart_str_appends(str, "clone");
2289+
smart_str_appendc(str, '(');
2290+
zend_ast_export_ex(str, ast->child[0], 0, indent);
2291+
if (ast->child[1]) {
2292+
smart_str_appends(str, ", ");
2293+
zend_ast_export_ex(str, ast->child[1], 0, indent);
2294+
}
2295+
smart_str_appendc(str, ')');
2296+
break;
22892297
case ZEND_AST_PRINT:
22902298
PREFIX_OP("print ", 60, 61);
22912299
case ZEND_AST_INCLUDE_OR_EVAL:

0 commit comments

Comments
 (0)