Skip to content

Commit

Permalink
[VarDumper] #131135: Use \ReflectionReference for determining if a va…
Browse files Browse the repository at this point in the history
…lue is reference(php7.4 only).
  • Loading branch information
dorumd committed Apr 28, 2019
1 parent c3f57d0 commit bf8a9b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/Symfony/Component/VarDumper/Cloner/VarCloner.php
Expand Up @@ -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)])) {
Expand Down
15 changes: 14 additions & 1 deletion src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php
Expand Up @@ -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 [
Expand Down

0 comments on commit bf8a9b2

Please sign in to comment.