Get rid of invalid assertion and cleanup zend_call_method

Closes GH-8672
This commit is contained in:
Máté Kocsis 2022-06-01 10:13:33 +02:00
parent 01d84545e7
commit 6d96f39a68
No known key found for this signature in database
GPG key ID: FD055E41728BF310
4 changed files with 17 additions and 30 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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)

View file

@ -1,5 +1,7 @@
--TEST--
Calling a builtin function with 'static' return type from internal code
--EXTENSIONS--
zend_test
--FILE--
<?php
@ -11,15 +13,15 @@ enum IntIntStaticString : string {
case ThanksFor = "all the fish";
}
var_dump(zend_call_method("IntIntStaticInt", "from", 42));
var_dump(zend_call_method("IntIntStaticInt", "tryFrom", 42));
var_dump(zend_call_method("IntIntStaticString", "from", "all the fish"));
var_dump(zend_call_method("IntIntStaticString", "tryFrom", "all the fish"));
var_dump(zend_call_method(IntIntStaticInt::class, "from", 42));
var_dump(zend_call_method(IntIntStaticInt::class, "tryFrom", 42));
var_dump(zend_call_method(IntIntStaticString::class, "from", "all the fish"));
var_dump(zend_call_method(IntIntStaticString::class, "tryFrom", "all the fish"));
class StillReturnsStatic extends _ZendTestClass {}
var_dump(get_class(zend_call_method("_ZendTestClass", "returnsStatic")));
var_dump(get_class(zend_call_method("StillReturnsStatic", "returnsStatic")));
var_dump(get_class(zend_call_method(_ZendTestClass::class, "returnsStatic")));
var_dump(get_class(zend_call_method(StillReturnsStatic::class, "returnsStatic")));
--EXPECT--
enum(IntIntStaticInt::Life)