From 6d96f39a68bbe6bd8737ccb315f9072d82f6bd2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 1 Jun 2022 10:13:33 +0200 Subject: [PATCH] Get rid of invalid assertion and cleanup zend_call_method Closes GH-8672 --- ext/zend_test/test.c | 23 ++++--------------- ext/zend_test/test.stub.php | 2 +- ext/zend_test/test_arginfo.h | 8 +++---- .../internal-call-internal-static-return.phpt | 14 ++++++----- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index c1269c7b187..617d81fa25d 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -281,35 +281,20 @@ static ZEND_FUNCTION(zend_iterable) /* Call a method on a class or object using zend_call_method() */ static ZEND_FUNCTION(zend_call_method) { - zval *class_or_object; - zend_string *method_name; - zval *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_ZVAL(class_or_object) + Z_PARAM_CLASS(ce) Z_PARAM_STR(method_name) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(arg1) Z_PARAM_ZVAL(arg2) ZEND_PARSE_PARAMETERS_END(); - 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); + zend_call_method(NULL, 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 c9c7e39ddcf..9a49d31fa97 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -114,7 +114,7 @@ namespace { function zend_get_current_func_name(): string {} - function zend_call_method(object|string $clsOrObject, string $method, mixed $arg1 = null, mixed $arg2 = null): mixed {} + function zend_call_method(string $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 0e7721a3fd5..ebc4076daca 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: 1be3dba6b0638764bcf00cd695cb88a3e8a0a530 */ + * Stub hash: 27df6a7b48574b5c6c9a54c618fce300c7a8bd13 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -73,10 +73,10 @@ 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_MASK(0, clsOrObject, MAY_BE_OBJECT|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg1, IS_MIXED, 0, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg2, IS_MIXED, 0, "null") + ZEND_ARG_TYPE_INFO(0, arg1, IS_MIXED, 0) + ZEND_ARG_TYPE_INFO(0, arg2, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0) diff --git a/ext/zend_test/tests/internal-call-internal-static-return.phpt b/ext/zend_test/tests/internal-call-internal-static-return.phpt index 39097ad678d..bb44bcd48a6 100644 --- a/ext/zend_test/tests/internal-call-internal-static-return.phpt +++ b/ext/zend_test/tests/internal-call-internal-static-return.phpt @@ -1,5 +1,7 @@ --TEST-- Calling a builtin function with 'static' return type from internal code +--EXTENSIONS-- +zend_test --FILE--