diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 2c67f4c..7a40800 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -1016,23 +1016,23 @@ static v8::MaybeLocal v8js_wrap_object(v8::Isolate *isolate, zend_cl } if (has_json_serializable) { - void *ptr; - zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, ptr) { - zend_function *method_ptr = reinterpret_cast(ptr); - if (strcmp(ZSTR_VAL(method_ptr->common.function_name), "jsonSerialize") == 0) { - v8::Local method_name = V8JS_SYM("toJSON"); - v8::Local ft; + zend_string *jsonserialize_str = zend_string_init + ("jsonSerialize", sizeof("jsonSerialize") - 1, 0); + zend_function *jsonserialize_method_ptr = reinterpret_cast + (zend_hash_find_ptr_lc(&ce->function_table, jsonserialize_str)); + if (jsonserialize_method_ptr && + jsonserialize_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) { + v8::Local method_name = V8JS_SYM("toJSON"); + v8::Local ft; - ft = v8::FunctionTemplate::New(isolate, v8js_php_callback, - v8::External::New((isolate), method_ptr)); + ft = v8::FunctionTemplate::New(isolate, v8js_php_callback, + v8::External::New((isolate), jsonserialize_method_ptr)); - v8js_function_tmpl_t *persistent_ft = &ctx->method_tmpls[std::make_pair(ce, method_ptr)]; - persistent_ft->Reset(isolate, ft); + v8js_function_tmpl_t *persistent_ft = &ctx->method_tmpls[std::make_pair(ce, jsonserialize_method_ptr)]; + persistent_ft->Reset(isolate, ft); - newobj.ToLocalChecked()->CreateDataProperty(v8_context, method_name, ft->GetFunction(v8_context).ToLocalChecked()); - } - } ZEND_HASH_FOREACH_END(); + newobj.ToLocalChecked()->CreateDataProperty(v8_context, method_name, ft->GetFunction(v8_context).ToLocalChecked()); + } } if (ce == zend_ce_closure && !newobj.IsEmpty()) {