Skip to content

Commit fbd3017

Browse files
GH-21754: sapi/cli: avoid deprecation messages with --rf and methods (#21758)
1 parent 6c5bed3 commit fbd3017

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
@@ -12,6 +12,10 @@ PHP NEWS
1212
self::/parent::/static:: callables if the error handler throws). (macoaure)
1313
. Fixed bug GH-21603 (Missing addref for __unset). (ilutov)
1414

15+
- CLI:
16+
. Fixed bug GH-21754 (`--rf` command line option with a method triggers
17+
ext/reflection deprecation warnings). (DanielEScherzer)
18+
1519
- Curl:
1620
. Add support for brotli and zstd on Windows. (Shivam Mathur)
1721

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: 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(`$php -n --rf unknown`);
1313
var_dump(`$php -n --rf echo`);
1414
var_dump(`$php -n --rf phpinfo`);
15+
// Regression tests for https://github.com/php/php-src/issues/21754
16+
var_dump(`$php -n --rf ReflectionMethod::__construct`);
17+
var_dump(`$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)