Skip to content

Commit 1c6c7bc

Browse files
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: phpGH-21754: sapi/cli: avoid deprecation messages with `--rf` and methods (php#21758)
2 parents be9f26d + fbd3017 commit 1c6c7bc

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
self::/parent::/static:: callables if the error handler throws). (macoaure)
1616
. Fixed bug GH-21603 (Missing addref for __unset). (ilutov)
1717

18+
- CLI:
19+
. Fixed bug GH-21754 (`--rf` command line option with a method triggers
20+
ext/reflection deprecation warnings). (DanielEScherzer)
21+
1822
- Curl:
1923
. Add support for brotli and zstd on Windows. (Shivam Mathur)
2024

sapi/cli/php_cli.c

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

10601060
ZVAL_STRING(&arg, reflection_what);
1061-
object_init_ex(&ref, pce);
10621061

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

10691081
if (EG(exception)) {
10701082
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)