Skip to content

Commit 109ae05

Browse files
committed
zend_language_parser: Support every argument syntax for clone()
1 parent aab2815 commit 109ae05

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

Zend/tests/clone/ast.phpt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,60 @@ try {
1818
echo $e->getMessage(), PHP_EOL;
1919
}
2020

21+
try {
22+
assert(false && $y = clone($x, ));
23+
} catch (Error $e) {
24+
echo $e->getMessage(), PHP_EOL;
25+
}
26+
27+
try {
28+
assert(false && $y = clone($x, [ "foo" => $foo, "bar" => $bar ]));
29+
} catch (Error $e) {
30+
echo $e->getMessage(), PHP_EOL;
31+
}
32+
33+
try {
34+
assert(false && $y = clone($x, $array));
35+
} catch (Error $e) {
36+
echo $e->getMessage(), PHP_EOL;
37+
}
38+
39+
try {
40+
assert(false && $y = clone($x, $array, $extraParameter, $trailingComma, ));
41+
} catch (Error $e) {
42+
echo $e->getMessage(), PHP_EOL;
43+
}
44+
45+
try {
46+
assert(false && $y = clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
47+
} catch (Error $e) {
48+
echo $e->getMessage(), PHP_EOL;
49+
}
50+
51+
try {
52+
assert(false && $y = clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
53+
} catch (Error $e) {
54+
echo $e->getMessage(), PHP_EOL;
55+
}
56+
57+
try {
58+
assert(false && $y = clone(object: $x));
59+
} catch (Error $e) {
60+
echo $e->getMessage(), PHP_EOL;
61+
}
62+
63+
try {
64+
assert(false && $y = clone(object: $x, [ "foo" => $foo, "bar" => $bar ]));
65+
} catch (Error $e) {
66+
echo $e->getMessage(), PHP_EOL;
67+
}
68+
69+
try {
70+
assert(false && $y = clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]));
71+
} catch (Error $e) {
72+
echo $e->getMessage(), PHP_EOL;
73+
}
74+
2175
try {
2276
assert(false && $y = clone(...));
2377
} catch (Error $e) {
@@ -28,4 +82,13 @@ try {
2882
--EXPECT--
2983
assert(false && ($y = \clone($x)))
3084
assert(false && ($y = \clone($x)))
85+
assert(false && ($y = \clone($x)))
86+
assert(false && ($y = \clone($x, ['foo' => $foo, 'bar' => $bar])))
87+
assert(false && ($y = \clone($x, $array)))
88+
assert(false && ($y = \clone($x, $array, $extraParameter, $trailingComma)))
89+
assert(false && ($y = \clone(object: $x, withProperties: ['foo' => $foo, 'bar' => $bar])))
90+
assert(false && ($y = \clone($x, withProperties: ['foo' => $foo, 'bar' => $bar])))
91+
assert(false && ($y = \clone(object: $x)))
92+
assert(false && ($y = \clone(object: $x, ['foo' => $foo, 'bar' => $bar])))
93+
assert(false && ($y = \clone(...['object' => $x, 'withProperties' => ['foo' => $foo, 'bar' => $bar]])))
3194
assert(false && ($y = \clone(...)))

Zend/zend_language_parser.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
4646
%define api.pure full
4747
%define api.value.type {zend_parser_stack_elem}
4848
%define parse.error verbose
49-
%expect 0
49+
%expect 1
5050

5151
%destructor { zend_ast_destroy($$); } <ast>
5252
%destructor { if ($$) zend_string_release_ex($$, 0); } <str>
@@ -1228,10 +1228,10 @@ expr:
12281228
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
12291229
| variable '=' ampersand variable
12301230
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
1231-
| T_CLONE '(' T_ELLIPSIS ')' {
1231+
| T_CLONE argument_list {
12321232
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
12331233
name->attr = ZEND_NAME_FQ;
1234-
$$ = zend_ast_create(ZEND_AST_CALL, name, zend_ast_create_fcc());
1234+
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
12351235
}
12361236
| T_CLONE expr {
12371237
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));

0 commit comments

Comments
 (0)