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