Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57f5df5

Browse files
bug #43270 [VarDumper] Fix handling of "new" in initializers on PHP 8.1 (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Fix handling of "new" in initializers on PHP 8.1 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of #41552 | License | MIT | Doc PR | - Commits ------- f617c0b [VarDumper] Fix handling of "new" in initializers on PHP 8.1
2 parents 4169843 + f617c0b commit 57f5df5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ public static function getSignature(array $a)
356356
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
357357
} elseif (\is_bool($v)) {
358358
$signature .= $v ? 'true' : 'false';
359+
} elseif (\is_object($v)) {
360+
$signature .= 'new '.substr(strrchr('\\'.get_debug_type($v), '\\'), 1);
359361
} else {
360362
$signature .= $v;
361363
}

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,27 @@ public function testGenerator()
586586
$this->assertDumpMatchesFormat($expectedDump, $generator);
587587
}
588588

589+
/**
590+
* @requires PHP 8.1
591+
*/
592+
public function testNewInInitializer()
593+
{
594+
$f = eval('return function ($a = new stdClass()) {};');
595+
$line = __LINE__ - 1;
596+
597+
$this->assertDumpMatchesFormat(
598+
<<<EOTXT
599+
Closure(\$a = new stdClass) {
600+
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
601+
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
602+
file: "%sReflectionCasterTest.php($line) : eval()'d code"
603+
line: "1 to 1"
604+
}
605+
EOTXT
606+
, $f
607+
);
608+
}
609+
589610
public static function stub(): void
590611
{
591612
}

0 commit comments

Comments
 (0)