Skip to content

Commit d033d5c

Browse files
committed
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.
1 parent 9acebe1 commit d033d5c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/reflection/php_reflection.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,10 @@ static void reflection_class_constant_factory(zend_string *name_str, zend_class_
14321432

14331433
static int get_parameter_default(zval *result, parameter_reference *param) {
14341434
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
1435+
if (param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO) {
1436+
/* We don't have a way to determine the default value for this case right now. */
1437+
return FAILURE;
1438+
}
14351439
return zend_get_default_from_internal_arg_info(
14361440
result, (zend_internal_arg_info *) param->arg_info);
14371441
} else {
@@ -2717,7 +2721,8 @@ ZEND_METHOD(ReflectionParameter, isDefaultValueAvailable)
27172721
GET_REFLECTION_OBJECT_PTR(param);
27182722

27192723
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
2720-
RETURN_BOOL(((zend_internal_arg_info*) (param->arg_info))->default_value);
2724+
RETURN_BOOL(!(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)
2725+
&& ((zend_internal_arg_info*) (param->arg_info))->default_value);
27212726
} else {
27222727
zval *default_value = get_default_from_recv((zend_op_array *)param->fptr, param->offset);
27232728
RETURN_BOOL(default_value != NULL);

ext/reflection/tests/default_value_internal_userland_arginfo.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ $closure = function ($b = 0) {};
66
$ro = new ReflectionObject($closure);
77
$rm = $ro->getMethod('__invoke');
88
echo $rm, "\n";
9+
10+
$rp = $rm->getParameters()[0];
11+
var_dump($rp->isDefaultValueAvailable());
12+
try {
13+
var_dump($rp->getDefaultValue());
14+
} catch (ReflectionException $e) {
15+
echo $e->getMessage(), "\n";
16+
}
917
?>
1018
--EXPECT--
1119
Method [ <internal> public method __invoke ] {
@@ -14,3 +22,6 @@ Method [ <internal> public method __invoke ] {
1422
Parameter #0 [ <optional> $b = <default> ]
1523
}
1624
}
25+
26+
bool(false)
27+
Internal error: Failed to retrieve the default value

0 commit comments

Comments
 (0)