Skip to content

Commit 676ad71

Browse files
committed
Allow named placeholder
1 parent 9f2e48b commit 676ad71

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/main/php/lang/ast/syntax/PHP.class.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,28 +1737,32 @@ public function arguments($parse) {
17371737
$parse->forward();
17381738
if (':' === $parse->token->value) {
17391739
$parse->forward();
1740-
$arguments[$token->value]= $this->expression($parse, 0);
1740+
$offset= $token->value;
17411741
} else {
17421742
array_unshift($parse->queue, $parse->token);
17431743
$parse->token= $token;
1744-
$arguments[]= $this->expression($parse, 0);
1744+
$offset= sizeof($arguments);
17451745
}
1746-
} else if ('?' === $parse->token->value) {
1746+
} else {
1747+
$offset= sizeof($arguments);
1748+
}
1749+
1750+
if ('?' === $parse->token->value) {
17471751
$callable= true;
1748-
$arguments[]= Placeholder::$ARGUMENT;
1752+
$arguments[$offset]= Placeholder::$ARGUMENT;
17491753
$parse->forward();
17501754
} else if ('...' === $parse->token->value) {
17511755
$parse->forward();
17521756

17531757
// Resolve ambiguity between unpack and variadic placeholder at the end of arguments
17541758
if (')' === $parse->token->value) {
17551759
$callable= true;
1756-
$arguments[]= Placeholder::$VARIADIC;
1760+
$arguments[$offset]= Placeholder::$VARIADIC;
17571761
} else {
1758-
$arguments[]= new UnpackExpression($this->expression($parse, 0), $parse->token->line);
1762+
$arguments[$offset]= new UnpackExpression($this->expression($parse, 0), $parse->token->line);
17591763
}
17601764
} else {
1761-
$arguments[]= $this->expression($parse, 0);
1765+
$arguments[$offset]= $this->expression($parse, 0);
17621766
}
17631767

17641768
if (',' === $parse->token->value) {

src/test/php/lang/ast/unittest/parse/InvokeTest.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ public function partial_function_application() {
132132
);
133133
}
134134

135+
#[Test]
136+
public function partial_function_application_named() {
137+
$this->assertParsed(
138+
[new CallableExpression(
139+
new Literal('str_replace', self::LINE),
140+
[new Literal('"test"', self::LINE), new Literal('"ok"', self::LINE), 'subject' => Placeholder::$ARGUMENT],
141+
self::LINE
142+
)],
143+
'str_replace("test", "ok", subject: ?);'
144+
);
145+
}
146+
135147
#[Test]
136148
public function chained_invocation_spanning_multiple_lines() {
137149
$expr= new InvokeExpression(

0 commit comments

Comments
 (0)