Skip to content

Commit 0fb4a9a

Browse files
Merge branch '5.1' into 5.2
* 5.1: Rename parameter of @method configureContainer [DependencyInjection] Support PHP 8 builtin types in CheckTypeDeclarationsPass [DependencyInjection] Fix InvalidParameterTypeException for function parameters [Notifier] Cleanup changelog (5.1) [VarDumper] fix mutating $GLOBALS while cloning it
2 parents c1f6cca + 048db95 commit 0fb4a9a

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

Cloner/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private function dumpItem(DumperInterface $dumper, Cursor $cursor, array &$refs,
331331
}
332332
$cursor->hardRefTo = $refs[$r];
333333
$cursor->hardRefHandle = $this->useRefHandles & $item->handle;
334-
$cursor->hardRefCount = $item->refCount;
334+
$cursor->hardRefCount = 0 < $item->handle ? $item->refCount : 0;
335335
}
336336
$cursor->attr = $item->attr;
337337
$type = $item->class ?: \gettype($item->value);

Cloner/VarCloner.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,19 @@ protected function doClone($var)
143143
if (Stub::ARRAY_ASSOC === $stub->class) {
144144
// Copies of $GLOBALS have very strange behavior,
145145
// let's detect them with some black magic
146-
$a[$gid] = true;
147-
148-
// Happens with copies of $GLOBALS
149-
if (isset($v[$gid])) {
146+
if (\PHP_VERSION_ID < 80100 && ($a[$gid] = true) && isset($v[$gid])) {
150147
unset($v[$gid]);
151148
$a = [];
152149
foreach ($v as $gk => &$gv) {
150+
if ($v === $gv) {
151+
unset($v);
152+
$v = new Stub();
153+
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
154+
$v->handle = -1;
155+
$gv = &$hardRefs[spl_object_id($v)];
156+
$gv = $v;
157+
}
158+
153159
$a[$gk] = &$gv;
154160
}
155161
unset($gv);

Tests/Dumper/CliDumperTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ public function testRefsInProperties()
411411
/**
412412
* @runInSeparateProcess
413413
* @preserveGlobalState disabled
414+
* @requires PHP < 8.1
414415
*/
415416
public function testSpecialVars56()
416417
{
@@ -425,11 +426,11 @@ public function testSpecialVars56()
425426
]
426427
]
427428
1 => array:1 [
428-
"GLOBALS" => &2 array:1 [
429-
"GLOBALS" => &2 array:1 [&2]
430-
]
429+
"GLOBALS" => & array:1 [ …1]
430+
]
431+
2 => &3 array:1 [
432+
"GLOBALS" => &3 array:1 [&3]
431433
]
432-
2 => &2 array:1 [&2]
433434
]
434435
EOTXT
435436
,
@@ -440,6 +441,7 @@ public function testSpecialVars56()
440441
/**
441442
* @runInSeparateProcess
442443
* @preserveGlobalState disabled
444+
* @requires PHP < 8.1
443445
*/
444446
public function testGlobals()
445447
{
@@ -462,11 +464,11 @@ public function testGlobals()
462464
<<<'EOTXT'
463465
array:2 [
464466
1 => array:1 [
465-
"GLOBALS" => &1 array:1 [
466-
"GLOBALS" => &1 array:1 [&1]
467-
]
467+
"GLOBALS" => & array:1 [ …1]
468+
]
469+
2 => &2 array:1 [
470+
"GLOBALS" => &2 array:1 [&2]
468471
]
469-
2 => &1 array:1 [&1]
470472
]
471473

472474
EOTXT
@@ -556,6 +558,6 @@ private function getSpecialVars()
556558
return $var;
557559
};
558560

559-
return [$var(), $GLOBALS, &$GLOBALS];
561+
return eval('return [$var(), $GLOBALS, &$GLOBALS];');
560562
}
561563
}

0 commit comments

Comments
 (0)