xref: /php-src/ext/reflection/tests/bug40431.phpt (revision 902d6439)
1--TEST--
2Bug #40431 (dynamic properties may cause crash in ReflectionProperty methods)
3--FILE--
4<?php
5
6echo "=== 1st test ===\n";
7$Obj = new stdClass;
8$Obj->value = 'value';
9$RefObj = new ReflectionObject($Obj);
10
11$props = $RefObj->getProperties();
12
13var_dump($props);
14var_dump($props[0]->isStatic());
15var_dump($props[0]->isPrivate());
16var_dump($props[0]->isPublic());
17var_dump($props[0]->isProtected());
18
19echo "=== 2nd test ===\n";
20
21class test1 {
22}
23
24#[AllowDynamicProperties]
25class test2 extends test1{
26}
27
28$Obj = new test2;
29$Obj->value = 'value';
30$RefObj = new ReflectionObject($Obj);
31
32$props = $RefObj->getProperties();
33
34var_dump($props);
35var_dump($props[0]->isStatic());
36var_dump($props[0]->isPrivate());
37var_dump($props[0]->isPublic());
38var_dump($props[0]->isProtected());
39
40echo "=== 3rd test ===\n";
41
42#[AllowDynamicProperties]
43class test3 {
44}
45
46$Obj = new test3;
47$Obj->value = 'value';
48$RefObj = new ReflectionObject($Obj);
49
50$props = $RefObj->getProperties();
51
52var_dump($props);
53var_dump($props[0]->isStatic());
54var_dump($props[0]->isPrivate());
55var_dump($props[0]->isPublic());
56var_dump($props[0]->isProtected());
57
58echo "=== 4th test ===\n";
59
60class test5 {
61    private $value = 1;
62}
63
64#[AllowDynamicProperties]
65class test4 extends test5{
66}
67
68$Obj = new test4;
69$Obj->value = 'value';
70$RefObj = new ReflectionObject($Obj);
71
72$props = $RefObj->getProperties();
73
74var_dump($props);
75var_dump($props[0]->isStatic());
76var_dump($props[0]->isPrivate());
77var_dump($props[0]->isPublic());
78var_dump($props[0]->isProtected());
79
80echo "Done\n";
81?>
82--EXPECTF--
83=== 1st test ===
84array(1) {
85  [0]=>
86  object(ReflectionProperty)#%d (2) {
87    ["name"]=>
88    string(5) "value"
89    ["class"]=>
90    string(8) "stdClass"
91  }
92}
93bool(false)
94bool(false)
95bool(true)
96bool(false)
97=== 2nd test ===
98array(1) {
99  [0]=>
100  object(ReflectionProperty)#%d (2) {
101    ["name"]=>
102    string(5) "value"
103    ["class"]=>
104    string(5) "test2"
105  }
106}
107bool(false)
108bool(false)
109bool(true)
110bool(false)
111=== 3rd test ===
112array(1) {
113  [0]=>
114  object(ReflectionProperty)#%d (2) {
115    ["name"]=>
116    string(5) "value"
117    ["class"]=>
118    string(5) "test3"
119  }
120}
121bool(false)
122bool(false)
123bool(true)
124bool(false)
125=== 4th test ===
126array(1) {
127  [0]=>
128  object(ReflectionProperty)#%d (2) {
129    ["name"]=>
130    string(5) "value"
131    ["class"]=>
132    string(5) "test4"
133  }
134}
135bool(false)
136bool(false)
137bool(true)
138bool(false)
139Done
140