Skip to content

Commit 81f143e

Browse files
DanielEScherzeriluuu1994
authored andcommitted
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
1 parent 819b198 commit 81f143e

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ PHP NEWS
8080
- Reflection:
8181
. Fixed bug GH-15902 (Core dumped in ext/reflection/php_reflection.c).
8282
(DanielEScherzer)
83+
. Fixed missing final and abstract flags when dumping properties.
84+
(DanielEScherzer)
8385

8486
- Standard:
8587
. Fixed bug #72666 (stat cache clearing inconsistent between file:// paths

ext/reflection/php_reflection.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,12 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha
948948
if (!prop) {
949949
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);
950950
} else {
951+
if (prop->flags & ZEND_ACC_ABSTRACT) {
952+
smart_str_appends(str, "abstract ");
953+
}
954+
if (prop->flags & ZEND_ACC_FINAL) {
955+
smart_str_appends(str, "final ");
956+
}
951957
/* These are mutually exclusive */
952958
switch (prop->flags & ZEND_ACC_PPP_MASK) {
953959
case ZEND_ACC_PUBLIC:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Output of properties indicates if they are abstract
3+
--FILE--
4+
<?php
5+
6+
abstract class Demo {
7+
abstract public $a { get; }
8+
public $b;
9+
}
10+
11+
$class = new ReflectionClass(Demo::class);
12+
echo $class;
13+
14+
$propA = new ReflectionProperty(Demo::class, 'a');
15+
echo $propA;
16+
17+
$propB = new ReflectionProperty(Demo::class, 'b');
18+
echo $propB;
19+
?>
20+
--EXPECTF--
21+
Class [ <user> <iterateable> abstract class Demo ] {
22+
@@ %s %d-%d
23+
24+
- Constants [0] {
25+
}
26+
27+
- Static properties [0] {
28+
}
29+
30+
- Static methods [0] {
31+
}
32+
33+
- Properties [2] {
34+
Property [ abstract public $a ]
35+
Property [ public $b = NULL ]
36+
}
37+
38+
- Methods [0] {
39+
}
40+
}
41+
Property [ abstract public $a ]
42+
Property [ public $b = NULL ]

ext/reflection/tests/asymmetric_visibility_flags.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool(true)
2626
bool(false)
2727
bool(true)
2828
bool(false)
29-
Property [ public private(set) int $bar ]
29+
Property [ final public private(set) int $bar ]
3030
bool(false)
3131
bool(true)
3232
bool(false)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Output of properties indicates if they are final
3+
--FILE--
4+
<?php
5+
6+
class Demo {
7+
final public $a;
8+
public $b;
9+
}
10+
11+
$class = new ReflectionClass(Demo::class);
12+
echo $class;
13+
14+
$propA = new ReflectionProperty(Demo::class, 'a');
15+
echo $propA;
16+
17+
$propB = new ReflectionProperty(Demo::class, 'b');
18+
echo $propB;
19+
?>
20+
--EXPECTF--
21+
Class [ <user> class Demo ] {
22+
@@ %s %d-%d
23+
24+
- Constants [0] {
25+
}
26+
27+
- Static properties [0] {
28+
}
29+
30+
- Static methods [0] {
31+
}
32+
33+
- Properties [2] {
34+
Property [ final public $a = NULL ]
35+
Property [ public $b = NULL ]
36+
}
37+
38+
- Methods [0] {
39+
}
40+
}
41+
Property [ final public $a = NULL ]
42+
Property [ public $b = NULL ]

0 commit comments

Comments
 (0)