From 81f143e71f2293468859961f5d8faccb2a3d7244 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 24 Feb 2025 10:17:14 -0800 Subject: [PATCH] Reflection: indicate final and abstract properties in string output Add "final" and "abstract" to the result of `_property_string()` when outputting the string representation of a `ReflectionClass` or `ReflectionProperty` instance Closes GH-17827 --- NEWS | 2 + ext/reflection/php_reflection.c | 6 +++ .../tests/abstract_property_indicated.phpt | 42 +++++++++++++++++++ .../tests/asymmetric_visibility_flags.phpt | 2 +- .../tests/final_property_indicated.phpt | 42 +++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 ext/reflection/tests/abstract_property_indicated.phpt create mode 100644 ext/reflection/tests/final_property_indicated.phpt diff --git a/NEWS b/NEWS index ede93bdf118..1968cb701e9 100644 --- a/NEWS +++ b/NEWS @@ -80,6 +80,8 @@ PHP NEWS - Reflection: . Fixed bug GH-15902 (Core dumped in ext/reflection/php_reflection.c). (DanielEScherzer) + . Fixed missing final and abstract flags when dumping properties. + (DanielEScherzer) - Standard: . Fixed bug #72666 (stat cache clearing inconsistent between file:// paths diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 15bc8c3f244..f79d8a5181d 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -948,6 +948,12 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha if (!prop) { smart_str_append_printf(str, " public $%s", prop_name); } else { + if (prop->flags & ZEND_ACC_ABSTRACT) { + smart_str_appends(str, "abstract "); + } + if (prop->flags & ZEND_ACC_FINAL) { + smart_str_appends(str, "final "); + } /* These are mutually exclusive */ switch (prop->flags & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PUBLIC: diff --git a/ext/reflection/tests/abstract_property_indicated.phpt b/ext/reflection/tests/abstract_property_indicated.phpt new file mode 100644 index 00000000000..a70d88b7ece --- /dev/null +++ b/ext/reflection/tests/abstract_property_indicated.phpt @@ -0,0 +1,42 @@ +--TEST-- +Output of properties indicates if they are abstract +--FILE-- + +--EXPECTF-- +Class [ abstract class Demo ] { + @@ %s %d-%d + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [2] { + Property [ abstract public $a ] + Property [ public $b = NULL ] + } + + - Methods [0] { + } +} +Property [ abstract public $a ] +Property [ public $b = NULL ] diff --git a/ext/reflection/tests/asymmetric_visibility_flags.phpt b/ext/reflection/tests/asymmetric_visibility_flags.phpt index e6b171d3e76..580404decda 100644 --- a/ext/reflection/tests/asymmetric_visibility_flags.phpt +++ b/ext/reflection/tests/asymmetric_visibility_flags.phpt @@ -26,7 +26,7 @@ bool(true) bool(false) bool(true) bool(false) -Property [ public private(set) int $bar ] +Property [ final public private(set) int $bar ] bool(false) bool(true) bool(false) diff --git a/ext/reflection/tests/final_property_indicated.phpt b/ext/reflection/tests/final_property_indicated.phpt new file mode 100644 index 00000000000..d4e159749a9 --- /dev/null +++ b/ext/reflection/tests/final_property_indicated.phpt @@ -0,0 +1,42 @@ +--TEST-- +Output of properties indicates if they are final +--FILE-- + +--EXPECTF-- +Class [ class Demo ] { + @@ %s %d-%d + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [2] { + Property [ final public $a = NULL ] + Property [ public $b = NULL ] + } + + - Methods [0] { + } +} +Property [ final public $a = NULL ] +Property [ public $b = NULL ]