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)
38
38
$ maxItems = $ this ->maxItems ;
39
39
$ maxString = $ this ->maxString ;
40
40
$ 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
41
42
$ 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
43
44
// or null if the original value is used directly
44
45
$ zval = array ( // Main properties of the current value
45
46
'type ' => null ,
@@ -121,16 +122,20 @@ protected function doClone($var)
121
122
$ stub ->value = $ zval ['array_count ' ] ?: count ($ v );
122
123
123
124
$ 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 ;
127
129
128
130
// Happens with copies of $GLOBALS
129
- if ($ h !== $ stub ->value ) {
131
+ if (isset ($ v [$ gid ])) {
132
+ unset($ v [$ gid ]);
130
133
$ a = array ();
131
134
foreach ($ v as $ gk => &$ gv ) {
132
135
$ a [$ gk ] =& $ gv ;
133
136
}
137
+ } else {
138
+ $ a = $ v ;
134
139
}
135
140
}
136
141
break ;
Original file line number Diff line number Diff line change 18
18
*/
19
19
class VarClonerTest extends \PHPUnit_Framework_TestCase
20
20
{
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
+
21
64
public function testClone ()
22
65
{
23
66
$ json = json_decode ('{"1":{"var":"val"},"2":{"var":"val"}} ' );
You can’t perform that action at this time.
0 commit comments