Skip to content

Commit 55e77b8

Browse files
committed
zend_ast: Add AST printing support for clone property list
1 parent 480f8ef commit 55e77b8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Zend/tests/clone/ast.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
?>
34+
--EXPECT--
35+
assert(false && ($y = clone($x)))
36+
assert(false && ($y = clone($x)))
37+
assert(false && ($y = clone($x, ['foo' => $foo, 'bar' => $bar])))
38+
assert(false && ($y = clone($x, $array)))

Zend/zend_ast.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,15 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
23462346
smart_str_appendc(str, '`');
23472347
break;
23482348
case ZEND_AST_CLONE:
2349-
PREFIX_OP("clone ", 270, 271);
2349+
smart_str_appends(str, "clone");
2350+
smart_str_appendc(str, '(');
2351+
zend_ast_export_ex(str, ast->child[0], 0, indent);
2352+
if (ast->child[1]) {
2353+
smart_str_appends(str, ", ");
2354+
zend_ast_export_ex(str, ast->child[1], 0, indent);
2355+
}
2356+
smart_str_appendc(str, ')');
2357+
break;
23502358
case ZEND_AST_PRINT:
23512359
PREFIX_OP("print ", 60, 61);
23522360
case ZEND_AST_INCLUDE_OR_EVAL:

0 commit comments

Comments
 (0)