Skip to content

Commit be67a37

Browse files
Merge branch 'PHP-8.5'
* PHP-8.5: GH-21754: sapi/cli: avoid deprecation messages with `--rf` and methods (#21758)
2 parents edd99f7 + 1c6c7bc commit be67a37

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

sapi/cli/php_cli.c

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

10561056
ZVAL_STRING(&arg, reflection_what);
1057-
object_init_ex(&ref, pce);
10581057

10591058
memset(&execute_data, 0, sizeof(zend_execute_data));
10601059
execute_data.func = (zend_function *) &zend_pass_function;
10611060
EG(current_execute_data) = &execute_data;
1062-
zend_call_known_instance_method_with_1_params(
1063-
pce->constructor, Z_OBJ(ref), NULL, &arg);
1061+
// Avoid deprecation warnings from ReflectionMethod::__construct()
1062+
// with one argument
1063+
if (pce == reflection_method_ptr) {
1064+
zend_function *create_from_method = zend_hash_str_find_ptr(
1065+
&(pce->function_table),
1066+
"createfrommethodname",
1067+
strlen( "createFromMethodName" )
1068+
);
1069+
zend_call_known_function(
1070+
create_from_method, NULL, pce, &ref, 1, &arg, NULL);
1071+
} else {
1072+
object_init_ex(&ref, pce);
1073+
zend_call_known_instance_method_with_1_params(
1074+
pce->constructor, Z_OBJ(ref), NULL, &arg);
1075+
}
10641076

10651077
if (EG(exception)) {
10661078
zval rv;

sapi/cli/tests/004.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
1212
var_dump(shell_exec("$php -n --rf unknown"));
1313
var_dump(shell_exec("$php -n --rf echo"));
1414
var_dump(shell_exec("$php -n --rf phpinfo"));
15+
// Regression tests for https://github.com/php/php-src/issues/21754
16+
var_dump(shell_exec("$php -n --rf ReflectionMethod::__construct"));
17+
var_dump(shell_exec("$php -n --rf ReflectionMethod::missing"));
1518

1619
echo "Done\n";
1720
?>
@@ -28,5 +31,16 @@ string(155) "Function [ <internal:standard> function phpinfo ] {
2831
- Return [ true ]
2932
}
3033

34+
"
35+
string(213) "Method [ <internal:Reflection, ctor> public method __construct ] {
36+
37+
- Parameters [2] {
38+
Parameter #0 [ <required> object|string $objectOrMethod ]
39+
Parameter #1 [ <optional> ?string $method = null ]
40+
}
41+
}
42+
43+
"
44+
string(61) "Exception: Method ReflectionMethod::missing() does not exist
3145
"
3246
Done

0 commit comments

Comments
 (0)