Skip to content

Commit

Permalink
[VarDumper] Use \ReflectionReference for determining if a key is a re…
Browse files Browse the repository at this point in the history
…ference (php >= 7.4)
  • Loading branch information
dorumd authored and nicolas-grekas committed Jul 23, 2019
1 parent 376a8f4 commit e99a6b8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Symfony/Component/VarDumper/Cloner/VarCloner.php
Expand Up @@ -42,7 +42,7 @@ protected function doClone($var)
$currentDepth = 0; // Current tree depth
$currentDepthFinalIndex = 0; // Final $queue index for current tree depth
$minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached
$cookie = (object) []; // Unique object used to detect hard references
$cookie = (object) []; // Unique object used to detect hard references
$a = null; // Array cast for nested structures
$stub = null; // Stub capturing the main properties of an original item value
// or null if the original value is used directly
Expand Down Expand Up @@ -86,8 +86,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) {
$zvalIsRef = null !== \ReflectionReference::fromArrayElement($vals, $k);
} else {
$refs[$k] = $cookie;
$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

0 comments on commit e99a6b8

Please sign in to comment.