Skip to content

Commit 083f2bc

Browse files
Merge branch '5.3' into 5.4
* 5.3: [VarDumper] fix dumping typed references from properties Update README.md [Messenger] [Redis] Allow authentication with user and password [FrameworkBundle] Avoid secrets:decrypt-to-local command to fail fix missing classes
2 parents b94c3da + eaaea40 commit 083f2bc

File tree

3 files changed

+82
-20
lines changed

3 files changed

+82
-20
lines changed

Cloner/VarCloner.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,39 @@ protected function doClone($var)
6666
// $v is the original value or a stub object in case of hard references
6767

6868
if (\PHP_VERSION_ID >= 70400) {
69-
$zvalIsRef = null !== \ReflectionReference::fromArrayElement($vals, $k);
69+
$zvalRef = ($r = \ReflectionReference::fromArrayElement($vals, $k)) ? $r->getId() : null;
7070
} else {
7171
$refs[$k] = $cookie;
72-
$zvalIsRef = $vals[$k] === $cookie;
72+
$zvalRef = $vals[$k] === $cookie;
7373
}
7474

75-
if ($zvalIsRef) {
75+
if ($zvalRef) {
7676
$vals[$k] = &$stub; // Break hard references to make $queue completely
7777
unset($stub); // independent from the original structure
78-
if ($v instanceof Stub && isset($hardRefs[spl_object_id($v)])) {
79-
$vals[$k] = $refs[$k] = $v;
78+
if (\PHP_VERSION_ID >= 70400 ? null !== $vals[$k] = $hardRefs[$zvalRef] ?? null : $v instanceof Stub && isset($hardRefs[spl_object_id($v)])) {
79+
if (\PHP_VERSION_ID >= 70400) {
80+
$v = $vals[$k];
81+
} else {
82+
$refs[$k] = $vals[$k] = $v;
83+
}
8084
if ($v->value instanceof Stub && (Stub::TYPE_OBJECT === $v->value->type || Stub::TYPE_RESOURCE === $v->value->type)) {
8185
++$v->value->refCount;
8286
}
8387
++$v->refCount;
8488
continue;
8589
}
86-
$refs[$k] = $vals[$k] = new Stub();
87-
$refs[$k]->value = $v;
88-
$h = spl_object_id($refs[$k]);
89-
$hardRefs[$h] = &$refs[$k];
90-
$values[$h] = $v;
90+
$vals[$k] = new Stub();
91+
$vals[$k]->value = $v;
9192
$vals[$k]->handle = ++$refsCounter;
93+
94+
if (\PHP_VERSION_ID >= 70400) {
95+
$hardRefs[$zvalRef] = $vals[$k];
96+
} else {
97+
$refs[$k] = $vals[$k];
98+
$h = spl_object_id($refs[$k]);
99+
$hardRefs[$h] = &$refs[$k];
100+
$values[$h] = $v;
101+
}
92102
}
93103
// Create $stub when the original value $v can not be used directly
94104
// If $v is a nested structure, put that structure in array $a
@@ -154,12 +164,17 @@ protected function doClone($var)
154164
unset($v[$gid]);
155165
$a = [];
156166
foreach ($v as $gk => &$gv) {
157-
if ($v === $gv) {
167+
if ($v === $gv && (\PHP_VERSION_ID < 70400 || !isset($hardRefs[\ReflectionReference::fromArrayElement($v, $gk)->getId()]))) {
158168
unset($v);
159169
$v = new Stub();
160170
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
161171
$v->handle = -1;
162-
$gv = &$hardRefs[spl_object_id($v)];
172+
if (\PHP_VERSION_ID >= 70400) {
173+
$gv = &$a[$gk];
174+
$hardRefs[\ReflectionReference::fromArrayElement($a, $gk)->getId()] = &$gv;
175+
} else {
176+
$gv = &$hardRefs[spl_object_id($v)];
177+
}
163178
$gv = $v;
164179
}
165180

@@ -257,10 +272,12 @@ protected function doClone($var)
257272
}
258273
}
259274

260-
if ($zvalIsRef) {
261-
$refs[$k]->value = $stub;
262-
} else {
275+
if (!$zvalRef) {
263276
$vals[$k] = $stub;
277+
} elseif (\PHP_VERSION_ID >= 70400) {
278+
$hardRefs[$zvalRef]->value = $stub;
279+
} else {
280+
$refs[$k]->value = $stub;
264281
}
265282
}
266283

Tests/Cloner/VarClonerTest.php

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,55 @@ public function testPhp74()
499499
[p1] => 123
500500
[p2] => Symfony\Component\VarDumper\Cloner\Stub Object
501501
(
502-
[type] => 4
503-
[class] => stdClass
504-
[value] =>
502+
[type] => 1
503+
[class] =>
504+
[value] => Symfony\Component\VarDumper\Cloner\Stub Object
505+
(
506+
[type] => 4
507+
[class] => stdClass
508+
[value] =>
509+
[cut] => 0
510+
[handle] => %i
511+
[refCount] => 1
512+
[position] => 0
513+
[attr] => Array
514+
(
515+
)
516+
517+
)
518+
505519
[cut] => 0
506-
[handle] => %i
507-
[refCount] => 0
520+
[handle] => 1
521+
[refCount] => 1
522+
[position] => 0
523+
[attr] => Array
524+
(
525+
)
526+
527+
)
528+
529+
[p3] => Symfony\Component\VarDumper\Cloner\Stub Object
530+
(
531+
[type] => 1
532+
[class] =>
533+
[value] => Symfony\Component\VarDumper\Cloner\Stub Object
534+
(
535+
[type] => 4
536+
[class] => stdClass
537+
[value] =>
538+
[cut] => 0
539+
[handle] => %i
540+
[refCount] => 1
541+
[position] => 0
542+
[attr] => Array
543+
(
544+
)
545+
546+
)
547+
548+
[cut] => 0
549+
[handle] => 1
550+
[refCount] => 1
508551
[position] => 0
509552
[attr] => Array
510553
(

Tests/Fixtures/Php74.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ class Php74
66
{
77
public $p1 = 123;
88
public \stdClass $p2;
9+
public \stdClass $p3;
910

1011
public function __construct()
1112
{
1213
$this->p2 = new \stdClass();
14+
$this->p3 = &$this->p2;
1315
}
1416
}

0 commit comments

Comments
 (0)