Skip to content

Commit 2e2cbc8

Browse files
committed
zend_language_parser: Support all parameter syntax for clone()
1 parent f78a7c1 commit 2e2cbc8

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

Zend/tests/clone/ast.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ 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+
2127
try {
2228
assert(false && $y = clone($x, [ "foo" => $foo, "bar" => $bar ]));
2329
} catch (Error $e) {
@@ -30,6 +36,42 @@ try {
3036
echo $e->getMessage(), PHP_EOL;
3137
}
3238

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+
3375
try {
3476
assert(false && $y = clone(...));
3577
} catch (Error $e) {
@@ -40,6 +82,13 @@ try {
4082
--EXPECT--
4183
assert(false && ($y = \clone($x)))
4284
assert(false && ($y = \clone($x)))
85+
assert(false && ($y = \clone($x)))
4386
assert(false && ($y = \clone($x, ['foo' => $foo, 'bar' => $bar])))
4487
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]])))
4594
assert(false && ($y = \clone(...)))

Zend/zend_language_parser.y

Lines changed: 3 additions & 8 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,15 +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());
1235-
}
1236-
| T_CLONE '(' expr ',' expr ')' {
1237-
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
1238-
name->attr = ZEND_NAME_FQ;
1239-
$$ = zend_ast_create(ZEND_AST_CALL, name, zend_ast_create_list(2, ZEND_AST_ARG_LIST, $3, $5));
1234+
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
12401235
}
12411236
| T_CLONE expr {
12421237
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));

0 commit comments

Comments
 (0)