Skip to content

Commit e99a6b8

Browse files
dorumdnicolas-grekas
authored andcommitted
[VarDumper] Use \ReflectionReference for determining if a key is a reference (php >= 7.4)
1 parent 376a8f4 commit e99a6b8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Symfony/Component/VarDumper/Cloner/VarCloner.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function doClone($var)
4242
$currentDepth = 0; // Current tree depth
4343
$currentDepthFinalIndex = 0; // Final $queue index for current tree depth
4444
$minimumDepthReached = 0 === $minDepth; // Becomes true when minimum tree depth has been reached
45-
$cookie = (object) []; // Unique object used to detect hard references
45+
$cookie = (object) []; // Unique object used to detect hard references
4646
$a = null; // Array cast for nested structures
4747
$stub = null; // Stub capturing the main properties of an original item value
4848
// or null if the original value is used directly
@@ -86,8 +86,15 @@ protected function doClone($var)
8686
}
8787
foreach ($vals as $k => $v) {
8888
// $v is the original value or a stub object in case of hard references
89-
$refs[$k] = $cookie;
90-
if ($zvalIsRef = $vals[$k] === $cookie) {
89+
90+
if (\PHP_VERSION_ID >= 70400) {
91+
$zvalIsRef = null !== \ReflectionReference::fromArrayElement($vals, $k);
92+
} else {
93+
$refs[$k] = $cookie;
94+
$zvalIsRef = $vals[$k] === $cookie;
95+
}
96+
97+
if ($zvalIsRef) {
9198
$vals[$k] = &$stub; // Break hard references to make $queue completely
9299
unset($stub); // independent from the original structure
93100
if ($v instanceof Stub && isset($hardRefs[spl_object_hash($v)])) {

0 commit comments

Comments
 (0)