@@ -59,4 +59,43 @@ PHP_MSGPACK_API int php_msgpack_unserialize(
5959# define OBJ_FOR_PROP (zv ) Z_OBJ_P(zv)
6060#endif
6161
62+ #if PHP_VERSION_ID >= 80000
63+ # define IS_MAGIC_SERIALIZABLE (ce ) (ce && ce->__serialize)
64+ # define CALL_MAGIC_SERIALIZE (cep , zop , rvp ) zend_call_known_instance_method_with_0_params((cep)->__serialize, zop, rvp)
65+ # define CALL_MAGIC_UNSERIALIZE (cep , zop , rvp , zsdap ) zend_call_known_instance_method_with_1_params((cep)->__unserialize, zop, rvp, zsdap)
66+ #elif PHP_VERSION_ID >= 70400
67+ # define IS_MAGIC_SERIALIZABLE (ce ) (ce && zend_hash_str_exists(&ce->function_table, ZEND_STRL("__serialize")))
68+ # define CALL_MAGIC_SERIALIZE (cep , zop , rvp ) call_magic_serialize_fn(cep, zop, rvp, ZEND_STRL("__serialize"), 0, NULL)
69+ # define CALL_MAGIC_UNSERIALIZE (cep , zop , rvp , zsdap ) call_magic_serialize_fn(cep, zop, rvp, ZEND_STRL("__unserialize"), 1, zsdap)
70+ static inline void call_magic_serialize_fn (zend_class_entry * ce , zend_object * object , zval * retval_ptr , const char * fn_str , size_t fn_len , int param_count , zval * params ) {
71+ zval retval ;
72+ zend_fcall_info fci ;
73+ zend_fcall_info_cache fcic ;
74+
75+ fci .size = sizeof (fci );
76+ fci .object = object ;
77+ fci .retval = retval_ptr ? retval_ptr : & retval ;
78+ fci .param_count = param_count ;
79+ fci .params = params ;
80+ ZVAL_UNDEF (& fci .function_name ); /* Unused */
81+
82+ fcic .function_handler = zend_hash_str_find_ptr (& ce -> function_table , fn_str , fn_len );
83+ fcic .object = object ;
84+ fcic .called_scope = ce ;
85+
86+ int result = zend_call_function (& fci , & fcic );
87+ if (UNEXPECTED (result == FAILURE )) {
88+ if (!EG (exception )) {
89+ zend_error_noreturn (E_CORE_ERROR , "Couldn't execute method %s%s%s" ,
90+ fcic .function_handler -> common .scope ? ZSTR_VAL (fcic .function_handler -> common .scope -> name ) : "" ,
91+ fcic .function_handler -> common .scope ? "::" : "" , ZSTR_VAL (fcic .function_handler -> common .function_name ));
92+ }
93+ }
94+
95+ if (!retval_ptr ) {
96+ zval_ptr_dtor (& retval );
97+ }
98+ }
99+ #endif
100+
62101#endif /* PHP_MSGPACK_H */
0 commit comments