Skip to content

Commit

Permalink
[VarDumper] Fix handling of "new" in initializers on PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 2, 2021
1 parent 1f12cc0 commit 0f8c227
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public static function getSignature(array $a)
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
} elseif (\is_bool($v)) {
$signature .= $v ? 'true' : 'false';
} elseif (\is_object($v)) {
$signature .= 'new '.substr(strrchr('\\'.get_debug_type($v), '\\'), 1);
} else {
$signature .= $v;
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/Caster/ReflectionCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,27 @@ public function testGenerator()
$this->assertDumpMatchesFormat($expectedDump, $generator);
}

/**
* @requires PHP 8.1
*/
public function testNewInInitializer()
{
$f = eval('return function ($a = new stdClass()) {};');
$line = __LINE__ - 1;

$this->assertDumpMatchesFormat(
<<<EOTXT
Closure(\$a = new stdClass) {
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
file: "%sReflectionCasterTest.php($line) : eval()'d code"
line: "1 to 1"
}
EOTXT
, $f
);
}

public static function stub(): void
{
}
Expand Down

0 comments on commit 0f8c227

Please sign in to comment.