Skip to content

Commit ded8af5

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Reflection: indicate final and abstract properties in string output
2 parents babf7a3 + 81f143e commit ded8af5

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

ext/reflection/php_reflection.c

+6
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,12 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha
942942
if (!prop) {
943943
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);
944944
} else {
945+
if (prop->flags & ZEND_ACC_ABSTRACT) {
946+
smart_str_appends(str, "abstract ");
947+
}
948+
if (prop->flags & ZEND_ACC_FINAL) {
949+
smart_str_appends(str, "final ");
950+
}
945951
/* These are mutually exclusive */
946952
switch (prop->flags & ZEND_ACC_PPP_MASK) {
947953
case ZEND_ACC_PUBLIC:
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

+1-1
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)
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)