Fix reflection getDefaultValue() with user arg info

The default value is part of the op_array in that case, but we have
no way to access it. Fail gracefully.
This commit is contained in:
Nikita Popov 2020-11-12 11:02:04 +01:00
parent 9acebe14df
commit d033d5c07a
2 changed files with 17 additions and 1 deletions

View file

@ -1432,6 +1432,10 @@ static void reflection_class_constant_factory(zend_string *name_str, zend_class_
static int get_parameter_default(zval *result, parameter_reference *param) {
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
if (param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO) {
/* We don't have a way to determine the default value for this case right now. */
return FAILURE;
}
return zend_get_default_from_internal_arg_info(
result, (zend_internal_arg_info *) param->arg_info);
} else {
@ -2717,7 +2721,8 @@ ZEND_METHOD(ReflectionParameter, isDefaultValueAvailable)
GET_REFLECTION_OBJECT_PTR(param);
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
RETURN_BOOL(((zend_internal_arg_info*) (param->arg_info))->default_value);
RETURN_BOOL(!(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)
&& ((zend_internal_arg_info*) (param->arg_info))->default_value);
} else {
zval *default_value = get_default_from_recv((zend_op_array *)param->fptr, param->offset);
RETURN_BOOL(default_value != NULL);

View file

@ -6,6 +6,14 @@ $closure = function ($b = 0) {};
$ro = new ReflectionObject($closure);
$rm = $ro->getMethod('__invoke');
echo $rm, "\n";
$rp = $rm->getParameters()[0];
var_dump($rp->isDefaultValueAvailable());
try {
var_dump($rp->getDefaultValue());
} catch (ReflectionException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Method [ <internal> public method __invoke ] {
@ -14,3 +22,6 @@ Method [ <internal> public method __invoke ] {
Parameter #0 [ <optional> $b = <default> ]
}
}
bool(false)
Internal error: Failed to retrieve the default value