Skip to content

Commit 5f80c87

Browse files
committed
Fix '?' in ReflectionNamedType::getName() from ReflectionProperty::getSettableType()
Fixes GH-19187
1 parent f8196a5 commit 5f80c87

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ext/reflection/php_reflection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6517,7 +6517,7 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
65176517
/* Get-only virtual property can never be written to. */
65186518
if (prop->hooks && (prop->flags & ZEND_ACC_VIRTUAL) && !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
65196519
zend_type never_type = ZEND_TYPE_INIT_CODE(IS_NEVER, 0, 0);
6520-
reflection_type_factory(never_type, return_value, 0);
6520+
reflection_type_factory(never_type, return_value, 1);
65216521
return;
65226522
}
65236523

@@ -6527,15 +6527,15 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
65276527
if (!ZEND_TYPE_IS_SET(arg_info->type)) {
65286528
RETURN_NULL();
65296529
}
6530-
reflection_type_factory(arg_info->type, return_value, 0);
6530+
reflection_type_factory(arg_info->type, return_value, 1);
65316531
return;
65326532
}
65336533

65346534
/* Fall back to property type */
65356535
if (!ZEND_TYPE_IS_SET(ref->prop->type)) {
65366536
RETURN_NULL();
65376537
}
6538-
reflection_type_factory(ref->prop->type, return_value, 0);
6538+
reflection_type_factory(ref->prop->type, return_value, 1);
65396539
}
65406540

65416541
/* {{{ Returns whether property has a type */

ext/reflection/tests/gh19187.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-19187: ReflectionNamedType::getName() should not include nullable type
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public string|null $bar {
8+
set(string|null $value) => $value;
9+
}
10+
}
11+
12+
$reflProp = new ReflectionProperty(Foo::class, 'bar');
13+
echo $reflProp->getType()->getName(), "\n";
14+
echo $reflProp->getSettableType()->getName(), "\n";
15+
16+
?>
17+
--EXPECT--
18+
string
19+
string

0 commit comments

Comments
 (0)