1--TEST--
2Test usage of ReflectionProperty methods isDefault(), isDynamic(), getModifiers(), getDeclaringClass() and getDocComment().
3--INI--
4opcache.save_comments=1
5--FILE--
6<?php
7
8function reflectProperty($classOrObj, $property, $className = null) {
9    $className ??= $classOrObj;
10    $propInfo = new ReflectionProperty($classOrObj, $property);
11    echo "**********************************\n";
12    echo "Reflecting on property $className::$property\n\n";
13    echo "isDefault():\n";
14    var_dump($propInfo->isDefault());
15    echo "isDynamic():\n";
16    var_dump($propInfo->isDynamic());
17    echo "getModifiers():\n";
18    var_dump($propInfo->getModifiers());
19    echo "getDeclaringClass():\n";
20    var_dump($propInfo->getDeclaringClass());
21    echo "getDocComment():\n";
22    var_dump($propInfo->getDocComment());
23    echo "\n**********************************\n";
24}
25
26#[AllowDynamicProperties]
27class TestClass {
28    public $pub;
29    static public $stat = "static property";
30    /**
31     * This property has a comment.
32     */
33    protected $prot = 4;
34    private $priv = "keepOut";
35}
36
37reflectProperty("TestClass", "pub");
38reflectProperty("TestClass", "stat");
39reflectProperty("TestClass", "prot");
40reflectProperty("TestClass", "priv");
41
42$obj = new TestClass();
43$obj->dyn = 'dynamic';
44reflectProperty($obj, "dyn", "TestClass");
45
46?>
47--EXPECTF--
48**********************************
49Reflecting on property TestClass::pub
50
51isDefault():
52bool(true)
53isDynamic():
54bool(false)
55getModifiers():
56int(1)
57getDeclaringClass():
58object(ReflectionClass)#%d (1) {
59  ["name"]=>
60  string(9) "TestClass"
61}
62getDocComment():
63bool(false)
64
65**********************************
66**********************************
67Reflecting on property TestClass::stat
68
69isDefault():
70bool(true)
71isDynamic():
72bool(false)
73getModifiers():
74int(17)
75getDeclaringClass():
76object(ReflectionClass)#%d (1) {
77  ["name"]=>
78  string(9) "TestClass"
79}
80getDocComment():
81bool(false)
82
83**********************************
84**********************************
85Reflecting on property TestClass::prot
86
87isDefault():
88bool(true)
89isDynamic():
90bool(false)
91getModifiers():
92int(2)
93getDeclaringClass():
94object(ReflectionClass)#%d (1) {
95  ["name"]=>
96  string(9) "TestClass"
97}
98getDocComment():
99string(%d) "/**
100     * This property has a comment.
101     */"
102
103**********************************
104**********************************
105Reflecting on property TestClass::priv
106
107isDefault():
108bool(true)
109isDynamic():
110bool(false)
111getModifiers():
112int(4)
113getDeclaringClass():
114object(ReflectionClass)#%d (1) {
115  ["name"]=>
116  string(9) "TestClass"
117}
118getDocComment():
119bool(false)
120
121**********************************
122**********************************
123Reflecting on property TestClass::dyn
124
125isDefault():
126bool(false)
127isDynamic():
128bool(true)
129getModifiers():
130int(1)
131getDeclaringClass():
132object(ReflectionClass)#%d (1) {
133  ["name"]=>
134  string(9) "TestClass"
135}
136getDocComment():
137bool(false)
138
139**********************************
140