Skip to content

Support every argument syntax for clone() #18938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
zend_language_parser: Support every argument syntax for clone()
  • Loading branch information
TimWolla committed Jun 25, 2025
commit 109ae05194fe56767729cb49d1cea103941c0fd5
63 changes: 63 additions & 0 deletions Zend/tests/clone/ast.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,60 @@ try {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, ));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, $array));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, $array, $extraParameter, $trailingComma, ));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x, [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(...));
} catch (Error $e) {
Expand All @@ -28,4 +82,13 @@ try {
--EXPECT--
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x, ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone($x, $array)))
assert(false && ($y = \clone($x, $array, $extraParameter, $trailingComma)))
assert(false && ($y = \clone(object: $x, withProperties: ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone($x, withProperties: ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone(object: $x)))
assert(false && ($y = \clone(object: $x, ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone(...['object' => $x, 'withProperties' => ['foo' => $foo, 'bar' => $bar]])))
assert(false && ($y = \clone(...)))
6 changes: 3 additions & 3 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%define api.pure full
%define api.value.type {zend_parser_stack_elem}
%define parse.error verbose
%expect 0
%expect 1

%destructor { zend_ast_destroy($$); } <ast>
%destructor { if ($$) zend_string_release_ex($$, 0); } <str>
Expand Down Expand Up @@ -1228,10 +1228,10 @@ expr:
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
| variable '=' ampersand variable
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
| T_CLONE '(' T_ELLIPSIS ')' {
| T_CLONE argument_list {
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
name->attr = ZEND_NAME_FQ;
$$ = zend_ast_create(ZEND_AST_CALL, name, zend_ast_create_fcc());
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
}
| T_CLONE expr {
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
Expand Down