From: Nikita Popov Date: Thu, 2 Apr 2020 09:05:04 +0000 (+0200) Subject: Show property type in reflection export X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5991d3382a63079524cf777c0bc43f1cc9c837c;p=php Show property type in reflection export --- diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e3d16fd3e0..018f97e462 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -595,7 +595,8 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_ } if (ZEND_TYPE_IS_SET(arg_info->type)) { zend_string *type_str = zend_type_to_string(arg_info->type); - smart_str_append_printf(str, "%s ", ZSTR_VAL(type_str)); + smart_str_append(str, type_str); + smart_str_appendc(str, ' '); zend_string_release(type_str); } if (ZEND_ARG_SEND_MODE(arg_info)) { @@ -843,6 +844,12 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha if (prop->flags & ZEND_ACC_STATIC) { smart_str_appends(str, "static "); } + if (ZEND_TYPE_IS_SET(prop->type)) { + zend_string *type_str = zend_type_to_string(prop->type); + smart_str_append(str, type_str); + smart_str_appendc(str, ' '); + zend_string_release(type_str); + } if (!prop_name) { const char *class_name; zend_unmangle_property_name(prop->name, &class_name, &prop_name); diff --git a/ext/reflection/tests/ReflectionClass_export_basic2.phpt b/ext/reflection/tests/ReflectionClass_export_basic2.phpt index c91c5d1d73..6f3c54c88a 100644 --- a/ext/reflection/tests/ReflectionClass_export_basic2.phpt +++ b/ext/reflection/tests/ReflectionClass_export_basic2.phpt @@ -5,6 +5,7 @@ ReflectionClass::__toString() - ensure inherited private props are hidden. Class c { private $a; static private $b; + public ?int $c = 42; } class d extends c {} @@ -14,7 +15,7 @@ echo new ReflectionClass("d"), "\n"; ?> --EXPECTF-- Class [ class c ] { - @@ %s 2-5 + @@ %s 2-6 - Constants [0] { } @@ -26,8 +27,9 @@ Class [ class c ] { - Static methods [0] { } - - Properties [1] { + - Properties [2] { Property [ private $a ] + Property [ public ?int $c ] } - Methods [0] { @@ -35,7 +37,7 @@ Class [ class c ] { } Class [ class d extends c ] { - @@ %s 7-7 + @@ %s 8-8 - Constants [0] { } @@ -46,7 +48,8 @@ Class [ class d extends c ] { - Static methods [0] { } - - Properties [0] { + - Properties [1] { + Property [ public ?int $c ] } - Methods [0] {