@@ -725,7 +725,7 @@ static void simdjson_encode_base64_object(smart_str *buf, const zval *val) {
725
725
726
726
static zend_result simdjson_encode_serializable_object (smart_str *buf, zval *val, simdjson_encoder *encoder) {
727
727
zend_class_entry *ce = Z_OBJCE_P (val);
728
- zval retval, fname ;
728
+ zval retval;
729
729
zend_result return_code;
730
730
731
731
#if PHP_VERSION_ID >= 80300
@@ -750,23 +750,11 @@ static zend_result simdjson_encode_serializable_object(smart_str *buf, zval *val
750
750
SIMDJSON_HASH_PROTECT_RECURSION (myht);
751
751
#endif
752
752
753
- ZVAL_INTERNED_STR (&fname, simdjson_json_serialize); // jsonSerialize
754
-
755
- if (FAILURE == call_user_function (NULL , val, &fname, &retval, 0 , NULL ) || Z_TYPE (retval) == IS_UNDEF) {
756
- if (!EG (exception)) {
757
- zend_throw_exception_ex (NULL , 0 , " Failed calling %s::jsonSerialize()" , ZSTR_VAL (ce->name ));
758
- }
759
- #if PHP_VERSION_ID >= 80300
760
- ZEND_GUARD_UNPROTECT_RECURSION (guard, JSON);
761
- #else
762
- SIMDJSON_HASH_UNPROTECT_RECURSION (myht);
763
- #endif
764
- return FAILURE;
765
- }
766
-
767
- if (EG (exception)) {
768
- /* Error already raised */
769
- zval_ptr_dtor (&retval);
753
+ zend_function *json_serialize_method = (zend_function*)zend_hash_find_ex_ptr (&ce->function_table , simdjson_json_serialize, 1 );
754
+ ZEND_ASSERT (json_serialize_method != NULL && " This should be guaranteed prior to calling this function" );
755
+ zend_call_known_instance_method_with_0_params (json_serialize_method, Z_OBJ_P (val), &retval);
756
+ /* An exception has occurred */
757
+ if (Z_TYPE (retval) == IS_UNDEF) {
770
758
#if PHP_VERSION_ID >= 80300
771
759
ZEND_GUARD_UNPROTECT_RECURSION (guard, JSON);
772
760
#else
@@ -775,8 +763,8 @@ static zend_result simdjson_encode_serializable_object(smart_str *buf, zval *val
775
763
return FAILURE;
776
764
}
777
765
778
- if (( Z_TYPE (retval) == IS_OBJECT) &&
779
- ( Z_OBJ (retval) == Z_OBJ_P (val) )) {
766
+ /* An exception has occurred */
767
+ if ( Z_TYPE (retval) == IS_OBJECT && Z_OBJ (retval) == Z_OBJ_P (val)) {
780
768
/* Handle the case where jsonSerialize does: return $this; by going straight to encode array */
781
769
#if PHP_VERSION_ID >= 80300
782
770
ZEND_GUARD_UNPROTECT_RECURSION (guard, JSON);
0 commit comments