Skip to content

Commit 6d96f39

Browse files
committed
Get rid of invalid assertion and cleanup zend_call_method
Closes GH-8672
1 parent 01d8454 commit 6d96f39

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

ext/zend_test/test.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -281,35 +281,20 @@ static ZEND_FUNCTION(zend_iterable)
281281
/* Call a method on a class or object using zend_call_method() */
282282
static ZEND_FUNCTION(zend_call_method)
283283
{
284-
zval *class_or_object;
285-
zend_string *method_name;
286-
zval *arg1 = NULL, *arg2 = NULL;
287-
zend_object *obj = NULL;
288284
zend_class_entry *ce = NULL;
285+
zend_string *method_name = NULL;
286+
zval *arg1 = NULL, *arg2 = NULL;
289287
int argc = ZEND_NUM_ARGS();
290288

291289
ZEND_PARSE_PARAMETERS_START(2, 4)
292-
Z_PARAM_ZVAL(class_or_object)
290+
Z_PARAM_CLASS(ce)
293291
Z_PARAM_STR(method_name)
294292
Z_PARAM_OPTIONAL
295293
Z_PARAM_ZVAL(arg1)
296294
Z_PARAM_ZVAL(arg2)
297295
ZEND_PARSE_PARAMETERS_END();
298296

299-
if (Z_TYPE_P(class_or_object) == IS_OBJECT) {
300-
obj = Z_OBJ_P(class_or_object);
301-
ce = obj->ce;
302-
} else {
303-
ZEND_ASSERT(Z_TYPE_P(class_or_object) == IS_STRING);
304-
ce = zend_lookup_class(Z_STR_P(class_or_object));
305-
if (!ce) {
306-
zend_error(E_ERROR, "Unknown class '%s'", Z_STRVAL_P(class_or_object));
307-
return;
308-
}
309-
}
310-
311-
ZEND_ASSERT((argc >= 2) && (argc <= 4));
312-
zend_call_method(obj, ce, NULL, ZSTR_VAL(method_name), ZSTR_LEN(method_name), return_value, argc - 2, arg1, arg2);
297+
zend_call_method(NULL, ce, NULL, ZSTR_VAL(method_name), ZSTR_LEN(method_name), return_value, argc - 2, arg1, arg2);
313298
}
314299

315300
static ZEND_FUNCTION(zend_get_unit_enum)

ext/zend_test/test.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function zend_test_parameter_with_attribute(string $parameter): int {}
114114

115115
function zend_get_current_func_name(): string {}
116116

117-
function zend_call_method(object|string $clsOrObject, string $method, mixed $arg1 = null, mixed $arg2 = null): mixed {}
117+
function zend_call_method(string $class, string $method, mixed $arg1 = UNKNOWN, mixed $arg2 = UNKNOWN): mixed {}
118118
}
119119

120120
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1be3dba6b0638764bcf00cd695cb88a3e8a0a530 */
2+
* Stub hash: 27df6a7b48574b5c6c9a54c618fce300c7a8bd13 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -73,10 +73,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_get_current_func_name, 0, 0
7373
ZEND_END_ARG_INFO()
7474

7575
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_call_method, 0, 2, IS_MIXED, 0)
76-
ZEND_ARG_TYPE_MASK(0, clsOrObject, MAY_BE_OBJECT|MAY_BE_STRING, NULL)
76+
ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0)
7777
ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 0)
78-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg1, IS_MIXED, 0, "null")
79-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg2, IS_MIXED, 0, "null")
78+
ZEND_ARG_TYPE_INFO(0, arg1, IS_MIXED, 0)
79+
ZEND_ARG_TYPE_INFO(0, arg2, IS_MIXED, 0)
8080
ZEND_END_ARG_INFO()
8181

8282
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0)

ext/zend_test/tests/internal-call-internal-static-return.phpt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Calling a builtin function with 'static' return type from internal code
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

@@ -11,15 +13,15 @@ enum IntIntStaticString : string {
1113
case ThanksFor = "all the fish";
1214
}
1315

14-
var_dump(zend_call_method("IntIntStaticInt", "from", 42));
15-
var_dump(zend_call_method("IntIntStaticInt", "tryFrom", 42));
16-
var_dump(zend_call_method("IntIntStaticString", "from", "all the fish"));
17-
var_dump(zend_call_method("IntIntStaticString", "tryFrom", "all the fish"));
16+
var_dump(zend_call_method(IntIntStaticInt::class, "from", 42));
17+
var_dump(zend_call_method(IntIntStaticInt::class, "tryFrom", 42));
18+
var_dump(zend_call_method(IntIntStaticString::class, "from", "all the fish"));
19+
var_dump(zend_call_method(IntIntStaticString::class, "tryFrom", "all the fish"));
1820

1921
class StillReturnsStatic extends _ZendTestClass {}
2022

21-
var_dump(get_class(zend_call_method("_ZendTestClass", "returnsStatic")));
22-
var_dump(get_class(zend_call_method("StillReturnsStatic", "returnsStatic")));
23+
var_dump(get_class(zend_call_method(_ZendTestClass::class, "returnsStatic")));
24+
var_dump(get_class(zend_call_method(StillReturnsStatic::class, "returnsStatic")));
2325

2426
--EXPECT--
2527
enum(IntIntStaticInt::Life)

0 commit comments

Comments
 (0)