Skip to content

Commit 018ed92

Browse files
committed
Dumper::format() placeholder ? must not be followed by \w
1 parent 8a3d6cb commit 018ed92

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ private function dumpLiteral(Literal $var, int $level): string
192192
*/
193193
public function format(string $statement, ...$args): string
194194
{
195-
$tokens = preg_split('#(\.\.\.\?:?|\$\?|->\?|::\?|\\\\\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
195+
$tokens = preg_split('#(\.\.\.\?:?|\$\?|->\?|::\?|\\\\\?|\?\*|\?(?!\w))#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
196196
$res = '';
197197
foreach ($tokens as $n => $token) {
198198
if ($n % 2 === 0) {
199199
$res .= $token;
200-
} elseif ($token === '\\?') {
200+
} elseif ($token === '\?') {
201201
$res .= '?';
202202
} elseif (!$args) {
203203
throw new Nette\InvalidArgumentException('Insufficient number of arguments.');

tests/PhpGenerator/Dumper.format().phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ require __DIR__ . '/../bootstrap.php';
1616
$dumper = new Dumper;
1717
Assert::same('func', $dumper->format('func'));
1818
Assert::same('func(1)', $dumper->format('func(?)', 1));
19+
Assert::same('fn(?string $x = 1)', $dumper->format('fn(?string $x = ?)', 1));
20+
Assert::same('fn(?string $x = 1)', $dumper->format('fn(\?string $x = ?)', 1));
1921
Assert::same('func(1 ? 2 : 3)', $dumper->format('func(1 \? 2 : 3)'));
2022
Assert::same('func([1, 2])', $dumper->format('func(?)', [1, 2]));
2123
Assert::same('func(1, 2)', $dumper->format('func(...?)', [1, 2]));

0 commit comments

Comments
 (0)