@@ -90,13 +90,12 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
90
90
91
91
$ properties = [];
92
92
$ sleep = null ;
93
- $ arrayValue = (array ) $ value ;
94
93
$ proto = Registry::$ prototypes [$ class ];
95
94
96
95
if (($ value instanceof \ArrayIterator || $ value instanceof \ArrayObject) && null !== $ proto ) {
97
96
// ArrayIterator and ArrayObject need special care because their "flags"
98
97
// option changes the behavior of the (array) casting operator.
99
- $ properties = self ::getArrayObjectProperties ($ value, $ arrayValue , $ proto );
98
+ [ $ arrayValue , $ properties] = self ::getArrayObjectProperties ($ value , $ proto );
100
99
101
100
// populates Registry::$prototypes[$class] with a new instance
102
101
Registry::getClassReflector ($ class , Registry::$ instantiableWithoutConstructor [$ class ], Registry::$ cloneable [$ class ]);
@@ -108,25 +107,23 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount
108
107
$ properties [] = $ value [$ v ];
109
108
}
110
109
$ properties = ['SplObjectStorage ' => ["\0" => $ properties ]];
110
+ $ arrayValue = (array ) $ value ;
111
111
} elseif ($ value instanceof \Serializable || $ value instanceof \__PHP_Incomplete_Class) {
112
112
++$ objectsCount ;
113
113
$ objectsPool [$ value ] = [$ id = \count ($ objectsPool ), serialize ($ value ), [], 0 ];
114
114
$ value = new Reference ($ id );
115
115
goto handle_value;
116
- }
117
-
118
- if (method_exists ($ class , '__sleep ' )) {
119
- if (!\is_array ($ sleep = $ value ->__sleep ())) {
120
- trigger_error ('serialize(): __sleep should return an array only containing the names of instance-variables to serialize ' , \E_USER_NOTICE );
121
- $ value = null ;
122
- goto handle_value;
123
- }
124
- foreach ($ sleep as $ name ) {
125
- if (property_exists ($ value , $ name ) && !$ reflector ->hasProperty ($ name )) {
126
- $ arrayValue [$ name ] = $ value ->$ name ;
116
+ } else {
117
+ if (method_exists ($ class , '__sleep ' )) {
118
+ if (!\is_array ($ sleep = $ value ->__sleep ())) {
119
+ trigger_error ('serialize(): __sleep should return an array only containing the names of instance-variables to serialize ' , \E_USER_NOTICE );
120
+ $ value = null ;
121
+ goto handle_value;
127
122
}
123
+ $ sleep = array_flip ($ sleep );
128
124
}
129
- $ sleep = array_flip ($ sleep );
125
+
126
+ $ arrayValue = (array ) $ value ;
130
127
}
131
128
132
129
$ proto = (array ) $ proto ;
@@ -370,13 +367,13 @@ private static function exportHydrator(Hydrator $value, string $indent, string $
370
367
* @param \ArrayIterator|\ArrayObject $value
371
368
* @param \ArrayIterator|\ArrayObject $proto
372
369
*/
373
- private static function getArrayObjectProperties ($ value , array & $ arrayValue , $ proto ): array
370
+ private static function getArrayObjectProperties ($ value , $ proto ): array
374
371
{
375
372
$ reflector = $ value instanceof \ArrayIterator ? 'ArrayIterator ' : 'ArrayObject ' ;
376
373
$ reflector = Registry::$ reflectors [$ reflector ] ?? Registry::getClassReflector ($ reflector );
377
374
378
375
$ properties = [
379
- $ arrayValue ,
376
+ $ arrayValue = ( array ) $ value ,
380
377
$ reflector ->getMethod ('getFlags ' )->invoke($ value ),
381
378
$ value instanceof \ArrayObject ? $ reflector ->getMethod ('getIteratorClass ' )->invoke ($ value ) : 'ArrayIterator ' ,
382
379
];
@@ -402,6 +399,6 @@ private static function getArrayObjectProperties($value, array &$arrayValue, $pr
402
399
$ properties = [$ reflector ->class => ["\0" => $ properties ]];
403
400
}
404
401
405
- return $ properties ;
402
+ return [ $ arrayValue , $ properties] ;
406
403
}
407
404
}
0 commit comments