Skip to content

Commit 8755b25

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: Php Inspections (EA Extended): squash all PR-13813 commits replaced the last remaining is_integer() call [2.3] [Config] [Console] [DependencyInjection] [DomCrawler] [Form] [HttpKernel] [PropertyAccess] [Security] [Translation] [Yaml] static code analysis, code cleanup [FrameworkBundle] simplify dep declaration [VarDumper] Fix "next element is already occupied" [Validator] Added missing galician (gl) translations [PropertyAccess] stop overwriting once a reference is reached (3rd) [OptionsResolver] Remove Unused Variable from Foreach Cycles [travis] Tests Security sub-components [Twig] bootstrap_3_layout.html.twig is usable as a trait [travis] Tests Security sub-components CS fixes [TwigBridge] Bootstrap Layout - Fix the label of checkbox cannot be empty [travis] test with php nightly Conflicts: .travis.yml src/Symfony/Bundle/FrameworkBundle/composer.json src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php
2 parents 6e1aeb4 + 61ee6c8 commit 8755b25

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

Cloner/VarCloner.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ protected function doClone($var)
3838
$maxItems = $this->maxItems;
3939
$maxString = $this->maxString;
4040
$cookie = (object) array(); // Unique object used to detect hard references
41+
$gid = uniqid(mt_rand(), true); // Unique string used to detect the special $GLOBALS variable
4142
$a = null; // Array cast for nested structures
42-
$stub = null; // Stub capturing the main properties of an original item value,
43+
$stub = null; // Stub capturing the main properties of an original item value
4344
// or null if the original value is used directly
4445
$zval = array( // Main properties of the current value
4546
'type' => null,
@@ -121,16 +122,20 @@ protected function doClone($var)
121122
$stub->value = $zval['array_count'] ?: count($v);
122123

123124
$a = $v;
124-
$a[] = null;
125-
$h = count($v);
126-
array_pop($a);
125+
126+
// Copies of $GLOBALS have very strange behavior,
127+
// let's detect them with some black magic
128+
$a[$gid] = true;
127129

128130
// Happens with copies of $GLOBALS
129-
if ($h !== $stub->value) {
131+
if (isset($v[$gid])) {
132+
unset($v[$gid]);
130133
$a = array();
131134
foreach ($v as $gk => &$gv) {
132135
$a[$gk] =& $gv;
133136
}
137+
} else {
138+
$a = $v;
134139
}
135140
}
136141
break;

Tests/VarClonerTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,49 @@
1818
*/
1919
class VarClonerTest extends \PHPUnit_Framework_TestCase
2020
{
21+
public function testMaxIntBoundary()
22+
{
23+
$data = array(PHP_INT_MAX => 123);
24+
25+
$cloner = new VarCloner();
26+
$clone = $cloner->cloneVar($data);
27+
28+
$expected = <<<EOTXT
29+
Symfony\Component\VarDumper\Cloner\Data Object
30+
(
31+
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
32+
(
33+
[0] => Array
34+
(
35+
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
36+
(
37+
[type] => array
38+
[class] => assoc
39+
[value] => 1
40+
[cut] => 0
41+
[handle] => 0
42+
[refCount] => 0
43+
[position] => 1
44+
)
45+
46+
)
47+
48+
[1] => Array
49+
(
50+
[%s] => 123
51+
)
52+
53+
)
54+
55+
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
56+
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
57+
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
58+
)
59+
60+
EOTXT;
61+
$this->assertSame(sprintf($expected, PHP_INT_MAX), print_r($clone, true));
62+
}
63+
2164
public function testClone()
2265
{
2366
$json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');

0 commit comments

Comments
 (0)