GET_REFLECTION_OBJECT_PTR(ce);
array_init(return_value);
- zend_hash_apply_with_arguments(&ce->function_table, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj);
- if (Z_TYPE(intern->obj) != IS_UNDEF && instanceof_function(ce, zend_ce_closure)) {
- zend_function *closure = zend_get_closure_invoke_method(Z_OBJ(intern->obj));
+ zend_hash_apply_with_arguments(&ce->function_table, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter);
+
+ if (instanceof_function(ce, zend_ce_closure)) {
+ zend_bool has_obj = Z_TYPE(intern->obj) != IS_UNDEF;
+ zval obj_tmp;
+ zend_object *obj;
+ if (!has_obj) {
+ object_init_ex(&obj_tmp, ce);
+ obj = Z_OBJ(obj_tmp);
+ } else {
+ obj = Z_OBJ(intern->obj);
+ }
+ zend_function *closure = zend_get_closure_invoke_method(obj);
if (closure) {
- _addmethod(closure, ce, return_value, filter, &intern->obj);
- _free_function(closure);
- _fix_closure_prototype(closure);
+ _addmethod(closure, ce, return_value, filter);
+ }
+ if (!has_obj) {
+ zval_ptr_dtor(&obj_tmp);
}
}
}