Skip to content

Commit b5991d3

Browse files
committed
Show property type in reflection export
1 parent 5430a46 commit b5991d3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

ext/reflection/php_reflection.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_
595595
}
596596
if (ZEND_TYPE_IS_SET(arg_info->type)) {
597597
zend_string *type_str = zend_type_to_string(arg_info->type);
598-
smart_str_append_printf(str, "%s ", ZSTR_VAL(type_str));
598+
smart_str_append(str, type_str);
599+
smart_str_appendc(str, ' ');
599600
zend_string_release(type_str);
600601
}
601602
if (ZEND_ARG_SEND_MODE(arg_info)) {
@@ -843,6 +844,12 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha
843844
if (prop->flags & ZEND_ACC_STATIC) {
844845
smart_str_appends(str, "static ");
845846
}
847+
if (ZEND_TYPE_IS_SET(prop->type)) {
848+
zend_string *type_str = zend_type_to_string(prop->type);
849+
smart_str_append(str, type_str);
850+
smart_str_appendc(str, ' ');
851+
zend_string_release(type_str);
852+
}
846853
if (!prop_name) {
847854
const char *class_name;
848855
zend_unmangle_property_name(prop->name, &class_name, &prop_name);

ext/reflection/tests/ReflectionClass_export_basic2.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ReflectionClass::__toString() - ensure inherited private props are hidden.
55
Class c {
66
private $a;
77
static private $b;
8+
public ?int $c = 42;
89
}
910

1011
class d extends c {}
@@ -14,7 +15,7 @@ echo new ReflectionClass("d"), "\n";
1415
?>
1516
--EXPECTF--
1617
Class [ <user> class c ] {
17-
@@ %s 2-5
18+
@@ %s 2-6
1819

1920
- Constants [0] {
2021
}
@@ -26,16 +27,17 @@ Class [ <user> class c ] {
2627
- Static methods [0] {
2728
}
2829

29-
- Properties [1] {
30+
- Properties [2] {
3031
Property [ <default> private $a ]
32+
Property [ <default> public ?int $c ]
3133
}
3234

3335
- Methods [0] {
3436
}
3537
}
3638

3739
Class [ <user> class d extends c ] {
38-
@@ %s 7-7
40+
@@ %s 8-8
3941

4042
- Constants [0] {
4143
}
@@ -46,7 +48,8 @@ Class [ <user> class d extends c ] {
4648
- Static methods [0] {
4749
}
4850

49-
- Properties [0] {
51+
- Properties [1] {
52+
Property [ <default> public ?int $c ]
5053
}
5154

5255
- Methods [0] {

0 commit comments

Comments
 (0)