Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Comment on lines +1060 to +1061
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be object_init_with_constructor :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is existing code that I didn't want to touch on bugfix branches, maybe for master though as a follow-up?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I went to go look at doing this for master and I don't think object_init_with_constructor() makes things any clearer - we know the parameter count already, we know the constructor is at ->constructor, etc. - so I don't think I'll send a patch to switch it, though no objections if you want to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really have any strong opinions

pce->constructor, Z_OBJ(ref), NULL, &arg);
}

if (EG(exception)) {
zval rv;
Expand Down
14 changes: 14 additions & 0 deletions sapi/cli/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
?>
Expand All @@ -28,5 +31,16 @@ string(155) "Function [ <internal:standard> function phpinfo ] {
- Return [ true ]
}

"
string(213) "Method [ <internal:Reflection, ctor> public method __construct ] {

- Parameters [2] {
Parameter #0 [ <required> object|string $objectOrMethod ]
Parameter #1 [ <optional> ?string $method = null ]
}
}

"
string(61) "Exception: Method ReflectionMethod::missing() does not exist
"
Done
Loading