[VarDumper] fix mutating $GLOBALS while cloning it
This commit is contained in:
parent
9b719ab13d
commit
384b0adf38
@ -335,7 +335,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
}
|
}
|
||||||
$cursor->hardRefTo = $refs[$r];
|
$cursor->hardRefTo = $refs[$r];
|
||||||
$cursor->hardRefHandle = $this->useRefHandles & $item->handle;
|
$cursor->hardRefHandle = $this->useRefHandles & $item->handle;
|
||||||
$cursor->hardRefCount = $item->refCount;
|
$cursor->hardRefCount = 0 < $item->handle ? $item->refCount : 0;
|
||||||
}
|
}
|
||||||
$cursor->attr = $item->attr;
|
$cursor->attr = $item->attr;
|
||||||
$type = $item->class ?: \gettype($item->value);
|
$type = $item->class ?: \gettype($item->value);
|
||||||
|
@ -159,13 +159,19 @@ class VarCloner extends AbstractCloner
|
|||||||
if (Stub::ARRAY_ASSOC === $stub->class) {
|
if (Stub::ARRAY_ASSOC === $stub->class) {
|
||||||
// Copies of $GLOBALS have very strange behavior,
|
// Copies of $GLOBALS have very strange behavior,
|
||||||
// let's detect them with some black magic
|
// let's detect them with some black magic
|
||||||
$a[$gid] = true;
|
if (\PHP_VERSION_ID < 80100 && ($a[$gid] = true) && isset($v[$gid])) {
|
||||||
|
|
||||||
// Happens with copies of $GLOBALS
|
|
||||||
if (isset($v[$gid])) {
|
|
||||||
unset($v[$gid]);
|
unset($v[$gid]);
|
||||||
$a = [];
|
$a = [];
|
||||||
foreach ($v as $gk => &$gv) {
|
foreach ($v as $gk => &$gv) {
|
||||||
|
if ($v === $gv) {
|
||||||
|
unset($v);
|
||||||
|
$v = new Stub();
|
||||||
|
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
|
||||||
|
$v->handle = -1;
|
||||||
|
$gv = &$hardRefs[spl_object_id($v)];
|
||||||
|
$gv = $v;
|
||||||
|
}
|
||||||
|
|
||||||
$a[$gk] = &$gv;
|
$a[$gk] = &$gv;
|
||||||
}
|
}
|
||||||
unset($gv);
|
unset($gv);
|
||||||
|
@ -439,6 +439,7 @@ EOTXT
|
|||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
|
* @requires PHP < 8.1
|
||||||
*/
|
*/
|
||||||
public function testSpecialVars56()
|
public function testSpecialVars56()
|
||||||
{
|
{
|
||||||
@ -453,11 +454,11 @@ array:3 [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
1 => array:1 [
|
1 => array:1 [
|
||||||
"GLOBALS" => &2 array:1 [
|
"GLOBALS" => & array:1 [ …1]
|
||||||
"GLOBALS" => &2 array:1 [&2]
|
]
|
||||||
]
|
2 => &3 array:1 [
|
||||||
|
"GLOBALS" => &3 array:1 [&3]
|
||||||
]
|
]
|
||||||
2 => &2 array:1 [&2]
|
|
||||||
]
|
]
|
||||||
EOTXT
|
EOTXT
|
||||||
,
|
,
|
||||||
@ -468,6 +469,7 @@ EOTXT
|
|||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
|
* @requires PHP < 8.1
|
||||||
*/
|
*/
|
||||||
public function testGlobals()
|
public function testGlobals()
|
||||||
{
|
{
|
||||||
@ -490,11 +492,11 @@ EOTXT
|
|||||||
<<<'EOTXT'
|
<<<'EOTXT'
|
||||||
array:2 [
|
array:2 [
|
||||||
1 => array:1 [
|
1 => array:1 [
|
||||||
"GLOBALS" => &1 array:1 [
|
"GLOBALS" => & array:1 [ …1]
|
||||||
"GLOBALS" => &1 array:1 [&1]
|
]
|
||||||
]
|
2 => &2 array:1 [
|
||||||
|
"GLOBALS" => &2 array:1 [&2]
|
||||||
]
|
]
|
||||||
2 => &1 array:1 [&1]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
EOTXT
|
EOTXT
|
||||||
@ -584,6 +586,6 @@ EOTXT
|
|||||||
return $var;
|
return $var;
|
||||||
};
|
};
|
||||||
|
|
||||||
return [$var(), $GLOBALS, &$GLOBALS];
|
return eval('return [$var(), $GLOBALS, &$GLOBALS];');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user