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