File tree Expand file tree Collapse file tree 2 files changed +53
-5
lines changed Expand file tree Collapse file tree 2 files changed +53
-5
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 1818 */
1919class 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"}} ' );
You can’t perform that action at this time.
0 commit comments