Skip to content

Commit 6af05f8

Browse files
committed
zend_language_parser: Add explanatory comment for clone_argument_list
1 parent 2adb409 commit 6af05f8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Zend/zend_language_parser.y

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,15 @@ non_empty_argument_list:
914914
{ $$ = zend_ast_list_add($1, $3); }
915915
;
916916

917+
/* `clone_argument_list` is necessary to resolve a parser ambiguity (shift-reduce conflict)
918+
* of `clone($expr)`, which could either be parsed as a function call with `$expr` as the first
919+
* argument or as a use of the `clone` language construct with an expression with useless
920+
* parenthesis. Both would be valid and result in the same AST / the same semantics.
921+
* `clone_argument_list` is defined in a way that an `expr` in the first position needs to
922+
* be followed by a `,` which is not valid syntax for a parenthesized `expr`, ensuring
923+
* that calling `clone()` with a single unnamed parameter is handled by the language construct
924+
* syntax.
925+
*/
917926
clone_argument_list:
918927
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
919928
| '(' non_empty_clone_argument_list possible_comma ')' { $$ = $2; }

0 commit comments

Comments
 (0)