diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index dbffaa0cdbc..1d9071f0da0 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -317,20 +317,34 @@ static ZEND_FUNCTION(zend_iterable) /* Call a method on a class or object using zend_call_method() */ static ZEND_FUNCTION(zend_call_method) { + zend_string *method_name; + zval *class_or_object, *arg1 = NULL, *arg2 = NULL; + zend_object *obj = NULL; zend_class_entry *ce = NULL; - zend_string *method_name = NULL; - zval *arg1 = NULL, *arg2 = NULL; int argc = ZEND_NUM_ARGS(); ZEND_PARSE_PARAMETERS_START(2, 4) - Z_PARAM_CLASS(ce) + Z_PARAM_ZVAL(class_or_object) Z_PARAM_STR(method_name) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(arg1) Z_PARAM_ZVAL(arg2) ZEND_PARSE_PARAMETERS_END(); - zend_call_method(NULL, ce, NULL, ZSTR_VAL(method_name), ZSTR_LEN(method_name), return_value, argc - 2, arg1, arg2); + if (Z_TYPE_P(class_or_object) == IS_OBJECT) { + obj = Z_OBJ_P(class_or_object); + ce = obj->ce; + } else { + ZEND_ASSERT(Z_TYPE_P(class_or_object) == IS_STRING); + ce = zend_lookup_class(Z_STR_P(class_or_object)); + if (!ce) { + zend_error(E_ERROR, "Unknown class '%s'", Z_STRVAL_P(class_or_object)); + return; + } + } + + ZEND_ASSERT((argc >= 2) && (argc <= 4)); + zend_call_method(obj, ce, NULL, ZSTR_VAL(method_name), ZSTR_LEN(method_name), return_value, argc - 2, arg1, arg2); } static ZEND_FUNCTION(zend_get_unit_enum) diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index 0182c517993..d58cea27dfc 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -119,7 +119,7 @@ namespace { function zend_get_current_func_name(): string {} - function zend_call_method(string $class, string $method, mixed $arg1 = UNKNOWN, mixed $arg2 = UNKNOWN): mixed {} + function zend_call_method(object|string $obj_or_class, string $method, mixed $arg1 = UNKNOWN, mixed $arg2 = UNKNOWN): mixed {} } namespace ZendTestNS { diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h index efe9ffaa348..0c575cf002a 100644 --- a/ext/zend_test/test_arginfo.h +++ b/ext/zend_test/test_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 8b170fa6a9b1cb0e48278373172235498de3c4dc */ + * Stub hash: 71d8e1e6e5a997e9b443fbce4136d0025b67830b */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -79,7 +79,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_get_current_func_name, 0, 0 ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_call_method, 0, 2, IS_MIXED, 0) - ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, obj_or_class, MAY_BE_OBJECT|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, arg1, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, arg2, IS_MIXED, 0)