@@ -199,6 +199,15 @@ ZEND_API bool zend_class_can_be_lazy(zend_class_entry *ce)
199199 return true;
200200}
201201
202+ static int zlo_hash_remove_dyn_props_func (zval * pDest )
203+ {
204+ if (Z_TYPE_P (pDest ) == IS_INDIRECT ) {
205+ return ZEND_HASH_APPLY_STOP ;
206+ }
207+
208+ return ZEND_HASH_APPLY_REMOVE ;
209+ }
210+
202211/* Make object 'obj' lazy. If 'obj' is NULL, create a lazy instance of
203212 * class 'reflection_ce' */
204213ZEND_API zend_object * zend_object_make_lazy (zend_object * obj ,
@@ -278,9 +287,17 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
278287
279288 GC_DEL_FLAGS (obj , IS_OBJ_DESTRUCTOR_CALLED );
280289
281- /* unset() dynamic properties */
282- zend_object_dtor_dynamic_properties (obj );
283- obj -> properties = NULL ;
290+ /* unset() dynamic properties. Do not NULL out obj->properties, as this
291+ * would be unexpected. */
292+ if (obj -> properties ) {
293+ if (UNEXPECTED (GC_REFCOUNT (obj -> properties ) > 1 )) {
294+ if (EXPECTED (!(GC_FLAGS (obj -> properties ) & IS_ARRAY_IMMUTABLE ))) {
295+ GC_DELREF (obj -> properties );
296+ }
297+ obj -> properties = zend_array_dup (obj -> properties );
298+ }
299+ zend_hash_reverse_apply (obj -> properties , zlo_hash_remove_dyn_props_func );
300+ }
284301
285302 /* unset() declared properties */
286303 for (int i = 0 ; i < reflection_ce -> default_properties_count ; i ++ ) {
0 commit comments