Skip to content

Commit 234d0b5

Browse files
GH-21754: sapi/cli: avoid deprecation messages with --rf and methods
1 parent e598732 commit 234d0b5

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

sapi/cli/php_cli.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,25 @@ static int do_cli(int argc, char **argv) /* {{{ */
10421042
}
10431043

10441044
ZVAL_STRING(&arg, reflection_what);
1045-
object_init_ex(&ref, pce);
10461045

10471046
memset(&execute_data, 0, sizeof(zend_execute_data));
10481047
execute_data.func = (zend_function *) &zend_pass_function;
10491048
EG(current_execute_data) = &execute_data;
1050-
zend_call_known_instance_method_with_1_params(
1051-
pce->constructor, Z_OBJ(ref), NULL, &arg);
1049+
// Avoid deprecation warnings from ReflectionMethod::__construct()
1050+
// with one argument
1051+
if (pce == reflection_method_ptr) {
1052+
zend_function *create_from_method = zend_hash_str_find_ptr(
1053+
&(pce->function_table),
1054+
"createfrommethodname",
1055+
strlen( "createFromMethodName" )
1056+
);
1057+
zend_call_known_function(
1058+
create_from_method, NULL, pce, &ref, 1, &arg, NULL);
1059+
} else {
1060+
object_init_ex(&ref, pce);
1061+
zend_call_known_instance_method_with_1_params(
1062+
pce->constructor, Z_OBJ(ref), NULL, &arg);
1063+
}
10521064

10531065
if (EG(exception)) {
10541066
zval rv;

sapi/cli/tests/004.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ string(155) "Function [ <internal:standard> function phpinfo ] {
3232
}
3333

3434
"
35-
string(371) "
36-
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0
37-
Method [ <internal:Reflection, ctor> public method __construct ] {
35+
string(213) "Method [ <internal:Reflection, ctor> public method __construct ] {
3836

3937
- Parameters [2] {
4038
Parameter #0 [ <required> object|string $objectOrMethod ]
@@ -43,8 +41,6 @@ Method [ <internal:Reflection, ctor> public method __construct ] {
4341
}
4442

4543
"
46-
string(219) "
47-
Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0
48-
Exception: Method ReflectionMethod::missing() does not exist
44+
string(61) "Exception: Method ReflectionMethod::missing() does not exist
4945
"
5046
Done

0 commit comments

Comments
 (0)