Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,6 @@ ZEND_FUNCTION(get_class_methods)
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
}
} ZEND_HASH_FOREACH_END();

if (ce == zend_ce_closure) {
ZVAL_STR_COPY(&method_name, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &method_name);
}
}
/* }}} */

Expand Down Expand Up @@ -1004,23 +999,10 @@ ZEND_FUNCTION(method_exists)
zend_object *obj = Z_OBJ_P(klass);
func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
if (func != NULL) {
if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
/* Returns true for the fake Closure's __invoke */
RETVAL_BOOL(func->common.scope == zend_ce_closure
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME));

zend_string_release_ex(func->common.function_name, 0);
zend_free_trampoline(func);
return;
}
ZEND_ASSERT((func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) == 0
&& "Closure::__invoke() should have been handled already");
RETURN_TRUE;
}
} else {
/* Returns true for fake Closure::__invoke */
if (ce == zend_ce_closure
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_closures.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public function call(object $newThis, mixed ...$args): mixed {}
public static function fromCallable(callable $callback): Closure {}

public static function getCurrent(): Closure {}

public function __invoke(mixed ...$values): mixed {}
}
8 changes: 7 additions & 1 deletion Zend/zend_closures_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3239,8 +3239,7 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
char *lcname = zend_str_tolower_dup(method_name, method_name_len);

zend_function *mptr;
if (ce == zend_ce_closure && orig_obj && (method_name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
&& memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
if (ce == zend_ce_closure && orig_obj && zend_string_equals_cstr(ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE), lcname, method_name_len)
&& (mptr = zend_get_closure_invoke_method(orig_obj)) != NULL)
{
/* Store the original closure object so we can validate it in invoke/invokeArgs.
Expand Down Expand Up @@ -4500,15 +4499,26 @@ ZEND_METHOD(ReflectionClass, getMethods)

GET_REFLECTION_OBJECT_PTR(ce);

array_init(return_value);
if (EXPECTED(ce != zend_ce_closure)) {
array_init_size(return_value, zend_hash_num_elements(&ce->function_table));
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) {
_addmethod(mptr, ce, Z_ARRVAL_P(return_value), filter);
} ZEND_HASH_FOREACH_END();
return;
}

/* For Closure we need to special case the __invoke() method.
* This is so we can get accurate information about parameters. */
if ((filter & ZEND_ACC_PUBLIC) == 0) {
RETURN_EMPTY_ARRAY();
}
array_init_size(return_value, zend_hash_num_elements(&ce->function_table));
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) {
if (zend_string_equals_ci(mptr->common.function_name, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) {
continue;
}
_addmethod(mptr, ce, Z_ARRVAL_P(return_value), filter);
} ZEND_HASH_FOREACH_END();

// No need for instanceof_function, the Closure class is final
if (ce != zend_ce_closure) {
return;
}
bool has_obj = Z_TYPE(intern->obj) != IS_UNDEF;
zval obj_tmp;
zend_object *obj;
Expand All @@ -4519,9 +4529,7 @@ ZEND_METHOD(ReflectionClass, getMethods)
obj = Z_OBJ(intern->obj);
}
zend_function *closure = zend_get_closure_invoke_method(obj);
if (closure
&& !_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter)
) {
if (closure && !_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter)) {
_free_function(closure);
}
if (!has_obj) {
Expand Down
Loading