@@ -468,7 +468,7 @@ static inline void php_var_serialize_string(smart_str *buf, char *str, int len)
468468 smart_str_appendl (buf , "\";" , 2 );
469469}
470470
471- static inline void php_var_serialize_class_name (smart_str * buf , zval * * struc TSRMLS_DC )
471+ static inline zend_bool php_var_serialize_class_name (smart_str * buf , zval * * struc TSRMLS_DC )
472472{
473473 PHP_CLASS_ATTRIBUTES ;
474474
@@ -479,16 +479,21 @@ static inline void php_var_serialize_class_name(smart_str *buf, zval **struc TSR
479479 smart_str_appendl (buf , class_name , name_len );
480480 smart_str_appendl (buf , "\":" , 2 );
481481 PHP_CLEANUP_CLASS_ATTRIBUTES ();
482+ return incomplete_class ;
482483}
483484
484485static void php_var_serialize_class (smart_str * buf , zval * * struc , zval * retval_ptr , HashTable * var_hash TSRMLS_DC )
485486{
486487 int count ;
488+ zend_bool incomplete_class ;
487489
488- php_var_serialize_class_name (buf , struc TSRMLS_CC );
490+ incomplete_class = php_var_serialize_class_name (buf , struc TSRMLS_CC );
489491 /* count after serializing name, since php_var_serialize_class_name
490492 changes the count if the variable is incomplete class */
491493 count = zend_hash_num_elements (HASH_OF (retval_ptr ));
494+ if (incomplete_class ) {
495+ -- count ;
496+ }
492497 smart_str_append_long (buf , count );
493498 smart_str_appendl (buf , ":{" , 2 );
494499
@@ -512,6 +517,9 @@ static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_p
512517 if (i == HASH_KEY_NON_EXISTANT )
513518 break ;
514519
520+ if (incomplete_class && strcmp (key , MAGIC_MEMBER ) == 0 ) {
521+ continue ;
522+ }
515523 zend_hash_get_current_data_ex (HASH_OF (retval_ptr ),
516524 (void * * ) & name , & pos );
517525
@@ -624,17 +632,21 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
624632 zval_ptr_dtor (& retval_ptr );
625633 /* fall-through */
626634 }
627- case IS_ARRAY :
635+ case IS_ARRAY : {
636+ zend_bool incomplete_class = 0 ;
628637 if (Z_TYPE_PP (struc ) == IS_ARRAY ) {
629638 smart_str_appendl (buf , "a:" , 2 );
630639 myht = HASH_OF (* struc );
631640 } else {
632- php_var_serialize_class_name (buf , struc TSRMLS_CC );
641+ incomplete_class = php_var_serialize_class_name (buf , struc TSRMLS_CC );
633642 myht = Z_OBJPROP_PP (struc );
634643 }
635644 /* count after serializing name, since php_var_serialize_class_name
636645 changes the count if the variable is incomplete class */
637646 i = myht ? zend_hash_num_elements (myht ) : 0 ;
647+ if (i > 0 && incomplete_class ) {
648+ -- i ;
649+ }
638650 smart_str_append_long (buf , i );
639651 smart_str_appendl (buf , ":{" , 2 );
640652 if (i > 0 ) {
@@ -651,6 +663,10 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
651663 if (i == HASH_KEY_NON_EXISTANT )
652664 break ;
653665
666+ if (incomplete_class && strcmp (key , MAGIC_MEMBER ) == 0 ) {
667+ continue ;
668+ }
669+
654670 switch (i ) {
655671 case HASH_KEY_IS_LONG :
656672 php_var_serialize_long (buf , index );
@@ -674,6 +690,7 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
674690 }
675691 smart_str_appendc (buf , '}' );
676692 return ;
693+ }
677694 default :
678695 smart_str_appendl (buf , "i:0;" , 4 );
679696 return ;
0 commit comments