Skip to content

Commit

Permalink
Fix fetching default value of internal function with userland arginfo
Browse files Browse the repository at this point in the history
"Fix" in the sense of "not crash". We aren't able to actually
display the default value for this case, as there's no way to
fetch the relevant information right now.
  • Loading branch information
nikic committed Aug 31, 2020
1 parent bef20d4 commit b4196ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,10 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_
if (!required) {
if (fptr->type == ZEND_INTERNAL_FUNCTION) {
smart_str_appends(str, " = ");
if (((zend_internal_arg_info*)arg_info)->default_value) {
/* TODO: We don't have a way to fetch the default value for an internal function
* with userland arg info. */
if (has_internal_arg_info(fptr)
&& ((zend_internal_arg_info*)arg_info)->default_value) {
smart_str_appends(str, ((zend_internal_arg_info*)arg_info)->default_value);
} else {
smart_str_appends(str, "<default>");
Expand Down
16 changes: 16 additions & 0 deletions ext/reflection/tests/default_value_internal_userland_arginfo.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Fetching default value of an internal trampoline function with userland arginfo
--FILE--
<?php
$closure = function ($b = 0) {};
$ro = new ReflectionObject($closure);
$rm = $ro->getMethod('__invoke');
echo $rm, "\n";
?>
--EXPECT--
Method [ <internal> public method __invoke ] {

- Parameters [1] {
Parameter #0 [ <optional> $b = <default> ]
}
}

0 comments on commit b4196ae

Please sign in to comment.