/* }}} */
/* {{{ _addmethod */
-static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter, zval *obj)
+static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter)
{
- zval method;
- size_t len = ZSTR_LEN(mptr->common.function_name);
- zend_function *closure;
if (mptr->common.fn_flags & filter) {
- if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(ZSTR_VAL(mptr->common.function_name), ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
- && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj))) != NULL)
- {
- _fix_closure_prototype(closure);
- mptr = closure;
- }
- /* don't assign closure_object since we only reflect the invoke handler
- method and not the closure definition itself, even if we have a
- closure */
+ zval method;
reflection_method_factory(ce, mptr, NULL, &method);
add_next_index_zval(retval, &method);
}
zend_class_entry *ce = *va_arg(args, zend_class_entry**);
zval *retval = va_arg(args, zval*);
long filter = va_arg(args, long);
- zval *obj = va_arg(args, zval *);
- _addmethod(mptr, ce, retval, filter, obj);
+ _addmethod(mptr, ce, retval, filter);
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
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) {
_fix_closure_prototype(closure);
- _addmethod(closure, ce, return_value, filter, &intern->obj);
- _free_function(closure);
+ _addmethod(closure, ce, return_value, filter);
+ }
+ if (!has_obj) {
+ zval_ptr_dtor(&obj_tmp);
}
}
}