diff --git a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php index f418aa089488d..92c4c34f28cca 100644 --- a/src/Symfony/Component/VarDumper/Cloner/VarCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/VarCloner.php @@ -85,9 +85,15 @@ protected function doClone($var) } } foreach ($vals as $k => $v) { - // $v is the original value or a stub object in case of hard references - $refs[$k] = $cookie; - if ($zvalIsRef = $vals[$k] === $cookie) { + if (\PHP_VERSION_ID >= 70400) { + // see https://wiki.php.net/rfc/reference_reflection + $zvalIsRef = null !== \ReflectionReference::fromArrayElement($vals, $k); + } else { + $refs[$k] = $cookie; // $v is the original value or a stub object in case of hard references + $zvalIsRef = $vals[$k] === $cookie; + } + + if ($zvalIsRef) { $vals[$k] = &$stub; // Break hard references to make $queue completely unset($stub); // independent from the original structure if ($v instanceof Stub && isset($hardRefs[\spl_object_hash($v)])) { diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index 9520b4fe102e7..68970b529e57f 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -230,7 +230,20 @@ public function testJsonCast() $var[] = &$v; $var[''] = 2; - if (\PHP_VERSION_ID >= 70200) { + if (\PHP_VERSION_ID >= 70400) { + $this->assertDumpMatchesFormat( + <<<'EOTXT' +array:4 [ + 0 => & {} + 1 => &2 null + 2 => &2 null + "" => 2 +] +EOTXT + , + $var + ); + } elseif (\PHP_VERSION_ID >= 70200) { $this->assertDumpMatchesFormat( <<<'EOTXT' array:4 [