From e598732e988f1183a7d39ff1754a8a3efb7168e4 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Tue, 14 Apr 2026 11:44:10 -0700 Subject: [PATCH 1/3] Add regression tests for current behavior --- sapi/cli/tests/004.phpt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sapi/cli/tests/004.phpt b/sapi/cli/tests/004.phpt index 83da934c8ff1..f99d4449bbf4 100644 --- a/sapi/cli/tests/004.phpt +++ b/sapi/cli/tests/004.phpt @@ -12,6 +12,9 @@ $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); var_dump(`$php -n --rf unknown`); var_dump(`$php -n --rf echo`); var_dump(`$php -n --rf phpinfo`); +// Regression tests for https://github.com/php/php-src/issues/21754 +var_dump(`$php -n --rf ReflectionMethod::__construct`); +var_dump(`$php -n --rf ReflectionMethod::missing`); echo "Done\n"; ?> @@ -28,5 +31,20 @@ string(155) "Function [ function phpinfo ] { - Return [ true ] } +" +string(371) " +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0 +Method [ public method __construct ] { + + - Parameters [2] { + Parameter #0 [ object|string $objectOrMethod ] + Parameter #1 [ ?string $method = null ] + } +} + +" +string(219) " +Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0 +Exception: Method ReflectionMethod::missing() does not exist " Done From 234d0b5fdde87df3476078aa5b89e018f54b558a Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Tue, 14 Apr 2026 12:53:37 -0700 Subject: [PATCH 2/3] GH-21754: sapi/cli: avoid deprecation messages with `--rf` and methods --- sapi/cli/php_cli.c | 18 +++++++++++++++--- sapi/cli/tests/004.phpt | 8 ++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 9444f3d6253a..4b19cf0604c6 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1042,13 +1042,25 @@ static int do_cli(int argc, char **argv) /* {{{ */ } ZVAL_STRING(&arg, reflection_what); - object_init_ex(&ref, pce); memset(&execute_data, 0, sizeof(zend_execute_data)); execute_data.func = (zend_function *) &zend_pass_function; EG(current_execute_data) = &execute_data; - zend_call_known_instance_method_with_1_params( - pce->constructor, Z_OBJ(ref), NULL, &arg); + // Avoid deprecation warnings from ReflectionMethod::__construct() + // with one argument + if (pce == reflection_method_ptr) { + zend_function *create_from_method = zend_hash_str_find_ptr( + &(pce->function_table), + "createfrommethodname", + strlen( "createFromMethodName" ) + ); + zend_call_known_function( + create_from_method, NULL, pce, &ref, 1, &arg, NULL); + } else { + object_init_ex(&ref, pce); + zend_call_known_instance_method_with_1_params( + pce->constructor, Z_OBJ(ref), NULL, &arg); + } if (EG(exception)) { zval rv; diff --git a/sapi/cli/tests/004.phpt b/sapi/cli/tests/004.phpt index f99d4449bbf4..69dc46b5b902 100644 --- a/sapi/cli/tests/004.phpt +++ b/sapi/cli/tests/004.phpt @@ -32,9 +32,7 @@ string(155) "Function [ function phpinfo ] { } " -string(371) " -Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0 -Method [ public method __construct ] { +string(213) "Method [ public method __construct ] { - Parameters [2] { Parameter #0 [ object|string $objectOrMethod ] @@ -43,8 +41,6 @@ Method [ public method __construct ] { } " -string(219) " -Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in Unknown on line 0 -Exception: Method ReflectionMethod::missing() does not exist +string(61) "Exception: Method ReflectionMethod::missing() does not exist " Done From 50c327451b3cfef03d780de3741434c781f54d07 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Tue, 14 Apr 2026 17:46:58 -0700 Subject: [PATCH 3/3] NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 8c423fe61cec..f3b3e3a6aa38 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ PHP NEWS self::/parent::/static:: callables if the error handler throws). (macoaure) . Fixed bug GH-21603 (Missing addref for __unset). (ilutov) +- CLI: + . Fixed bug GH-21754 (`--rf` command line option with a method triggers + ext/reflection deprecation warnings). (DanielEScherzer) + - Curl: . Add support for brotli and zstd on Windows. (Shivam Mathur)