Skip to content

Commit bf8a9b2

Browse files
committed
[VarDumper] #131135: Use \ReflectionReference for determining if a value is reference(php7.4 only).
1 parent c3f57d0 commit bf8a9b2

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ protected function doClone($var)
8585
}
8686
}
8787
foreach ($vals as $k => $v) {
88-
// $v is the original value or a stub object in case of hard references
89-
$refs[$k] = $cookie;
90-
if ($zvalIsRef = $vals[$k] === $cookie) {
88+
if (\PHP_VERSION_ID >= 70400) {
89+
// see https://wiki.php.net/rfc/reference_reflection
90+
$zvalIsRef = null !== \ReflectionReference::fromArrayElement($vals, $k);
91+
} else {
92+
$refs[$k] = $cookie; // $v is the original value or a stub object in case of hard references
93+
$zvalIsRef = $vals[$k] === $cookie;
94+
}
95+
96+
if ($zvalIsRef) {
9197
$vals[$k] = &$stub; // Break hard references to make $queue completely
9298
unset($stub); // independent from the original structure
9399
if ($v instanceof Stub && isset($hardRefs[\spl_object_hash($v)])) {

src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,20 @@ public function testJsonCast()
230230
$var[] = &$v;
231231
$var[''] = 2;
232232

233-
if (\PHP_VERSION_ID >= 70200) {
233+
if (\PHP_VERSION_ID >= 70400) {
234+
$this->assertDumpMatchesFormat(
235+
<<<'EOTXT'
236+
array:4 [
237+
0 => & {}
238+
1 => &2 null
239+
2 => &2 null
240+
"" => 2
241+
]
242+
EOTXT
243+
,
244+
$var
245+
);
246+
} elseif (\PHP_VERSION_ID >= 70200) {
234247
$this->assertDumpMatchesFormat(
235248
<<<'EOTXT'
236249
array:4 [

0 commit comments

Comments
 (0)