Skip to content

Commit 5a06842

Browse files
committed
Fix '?' in ReflectionNamedType::getName() from ReflectionProperty::getSettableType()
Fixes GH-19187 Closes GH-19201
1 parent 441e557 commit 5a06842

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Add support for CURLINFO_CONN_ID in curl_getinfo() (thecaliskan)
1212
. Add support for CURLINFO_QUEUE_TIME_T in curl_getinfo() (thecaliskan)
1313

14+
- Reflection:
15+
. Fixed bug GH-19187 (ReflectionNamedType::getName() prints nullable type when
16+
retrieved from ReflectionProperty::getSettableType()). (ilutov)
17+
1418
- Session:
1519
. Fixed GH-19197: build broken with ZEND_STRL usage with memcpy
1620
when implemented as macro. (David Carlier)

ext/reflection/php_reflection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,7 +6403,7 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
64036403
/* Get-only virtual property can never be written to. */
64046404
if (prop->hooks && (prop->flags & ZEND_ACC_VIRTUAL) && !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
64056405
zend_type never_type = ZEND_TYPE_INIT_CODE(IS_NEVER, 0, 0);
6406-
reflection_type_factory(never_type, return_value, 0);
6406+
reflection_type_factory(never_type, return_value, 1);
64076407
return;
64086408
}
64096409

@@ -6413,15 +6413,15 @@ ZEND_METHOD(ReflectionProperty, getSettableType)
64136413
if (!ZEND_TYPE_IS_SET(arg_info->type)) {
64146414
RETURN_NULL();
64156415
}
6416-
reflection_type_factory(arg_info->type, return_value, 0);
6416+
reflection_type_factory(arg_info->type, return_value, 1);
64176417
return;
64186418
}
64196419

64206420
/* Fall back to property type */
64216421
if (!ZEND_TYPE_IS_SET(ref->prop->type)) {
64226422
RETURN_NULL();
64236423
}
6424-
reflection_type_factory(ref->prop->type, return_value, 0);
6424+
reflection_type_factory(ref->prop->type, return_value, 1);
64256425
}
64266426

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

ext/reflection/tests/gh19187.phpt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
GH-19187: ReflectionNamedType::getName() should not include nullable type
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public string|null $a {
8+
set => $value;
9+
}
10+
public string|null $b {
11+
set(string|null $value) => $value;
12+
}
13+
public string|null $c {
14+
get => $this->c;
15+
}
16+
}
17+
18+
foreach ((new ReflectionClass(C::class))->getProperties() as $r) {
19+
$type = $r->getType();
20+
echo $type, "\n";
21+
echo $type->getName(), "\n";
22+
var_dump($type->allowsNull());
23+
echo "\n";
24+
25+
$settableType = $r->getSettableType();
26+
echo $settableType, "\n";
27+
echo $settableType->getName(), "\n";
28+
var_dump($settableType->allowsNull());
29+
echo "\n";
30+
}
31+
32+
?>
33+
--EXPECT--
34+
?string
35+
string
36+
bool(true)
37+
38+
?string
39+
string
40+
bool(true)
41+
42+
?string
43+
string
44+
bool(true)
45+
46+
?string
47+
string
48+
bool(true)
49+
50+
?string
51+
string
52+
bool(true)
53+
54+
?string
55+
string
56+
bool(true)

0 commit comments

Comments
 (0)