xref: /php-src/Zend/tests/property_hooks/dump.phpt (revision d76ef137)
1--TEST--
2Dumping object with property hooks
3--FILE--
4<?php
5
6class Test {
7    public $addedHooks = 'addedHooks';
8    public $virtual {
9        get { return strtoupper('virtual'); }
10    }
11    public $backed = 'backed' {
12        get { return strtoupper($this->backed); }
13        set { $this->backed = $value; }
14    }
15    public $writeOnly {
16        set {}
17    }
18    private $private = 'private' {
19        get { return strtoupper($this->private); }
20        set { $this->private = $value; }
21    }
22    private $changed = 'changed Test' {
23        get { return strtoupper($this->changed); }
24    }
25    public function dumpTest() {
26        var_dump($this);
27        var_dump(get_object_vars($this));
28        var_dump(get_mangled_object_vars($this));
29        var_export($this);
30        echo "\n";
31        echo json_encode($this), "\n";
32        var_dump((array) $this);
33    }
34}
35
36class Child extends Test {
37    public $addedHooks {
38        get { return strtoupper(parent::$addedHooks::get()); }
39    }
40    private $changed = 'changed Child' {
41        get { return strtoupper($this->changed); }
42    }
43    public function dumpChild() {
44        var_dump($this);
45        var_dump(get_object_vars($this));
46        var_export($this);
47        echo "\n";
48        echo json_encode($this), "\n";
49        var_dump((array) $this);
50    }
51}
52
53function dump($test) {
54    var_dump($test);
55    var_dump(get_object_vars($test));
56    var_export($test);
57    echo "\n";
58    echo json_encode($test), "\n";
59    var_dump((array) $test);
60}
61
62echo "dump(Test):\n";
63dump(new Test);
64
65echo "\n\ndump(Child):\n";
66dump(new Child);
67
68echo "\n\nChild::dumpTest():\n";
69(new Child)->dumpTest();
70
71echo "\n\nChild::dumpChild():\n";
72(new Child)->dumpChild();
73
74?>
75--EXPECTF--
76dump(Test):
77object(Test)#%d (4) {
78  ["addedHooks"]=>
79  string(10) "addedHooks"
80  ["backed"]=>
81  string(6) "backed"
82  ["private":"Test":private]=>
83  string(7) "private"
84  ["changed":"Test":private]=>
85  string(12) "changed Test"
86}
87array(3) {
88  ["addedHooks"]=>
89  string(10) "addedHooks"
90  ["virtual"]=>
91  string(7) "VIRTUAL"
92  ["backed"]=>
93  string(6) "BACKED"
94}
95\Test::__set_state(array(
96   'addedHooks' => 'addedHooks',
97   'virtual' => 'VIRTUAL',
98   'backed' => 'BACKED',
99   'private' => 'PRIVATE',
100   'changed' => 'CHANGED TEST',
101))
102{"addedHooks":"addedHooks","virtual":"VIRTUAL","backed":"BACKED"}
103array(4) {
104  ["addedHooks"]=>
105  string(10) "addedHooks"
106  ["backed"]=>
107  string(6) "backed"
108  ["%0Test%0private"]=>
109  string(7) "private"
110  ["%0Test%0changed"]=>
111  string(12) "changed Test"
112}
113
114
115dump(Child):
116object(Child)#%d (5) {
117  ["addedHooks"]=>
118  string(10) "addedHooks"
119  ["backed"]=>
120  string(6) "backed"
121  ["private":"Test":private]=>
122  string(7) "private"
123  ["changed":"Test":private]=>
124  string(12) "changed Test"
125  ["changed":"Child":private]=>
126  string(13) "changed Child"
127}
128array(3) {
129  ["addedHooks"]=>
130  string(10) "ADDEDHOOKS"
131  ["virtual"]=>
132  string(7) "VIRTUAL"
133  ["backed"]=>
134  string(6) "BACKED"
135}
136\Child::__set_state(array(
137   'addedHooks' => 'ADDEDHOOKS',
138   'virtual' => 'VIRTUAL',
139   'backed' => 'BACKED',
140   'private' => 'PRIVATE',
141   'changed' => 'CHANGED TEST',
142   'changed' => 'CHANGED CHILD',
143))
144{"addedHooks":"ADDEDHOOKS","virtual":"VIRTUAL","backed":"BACKED"}
145array(5) {
146  ["addedHooks"]=>
147  string(10) "addedHooks"
148  ["backed"]=>
149  string(6) "backed"
150  ["%0Test%0private"]=>
151  string(7) "private"
152  ["%0Test%0changed"]=>
153  string(12) "changed Test"
154  ["%0Child%0changed"]=>
155  string(13) "changed Child"
156}
157
158
159Child::dumpTest():
160object(Child)#%d (5) {
161  ["addedHooks"]=>
162  string(10) "addedHooks"
163  ["backed"]=>
164  string(6) "backed"
165  ["private":"Test":private]=>
166  string(7) "private"
167  ["changed":"Test":private]=>
168  string(12) "changed Test"
169  ["changed":"Child":private]=>
170  string(13) "changed Child"
171}
172array(5) {
173  ["addedHooks"]=>
174  string(10) "ADDEDHOOKS"
175  ["virtual"]=>
176  string(7) "VIRTUAL"
177  ["backed"]=>
178  string(6) "BACKED"
179  ["private"]=>
180  string(7) "PRIVATE"
181  ["changed"]=>
182  string(12) "CHANGED TEST"
183}
184array(5) {
185  ["addedHooks"]=>
186  string(10) "addedHooks"
187  ["backed"]=>
188  string(6) "backed"
189  ["%0Test%0private"]=>
190  string(7) "private"
191  ["%0Test%0changed"]=>
192  string(12) "changed Test"
193  ["%0Child%0changed"]=>
194  string(13) "changed Child"
195}
196\Child::__set_state(array(
197   'addedHooks' => 'ADDEDHOOKS',
198   'virtual' => 'VIRTUAL',
199   'backed' => 'BACKED',
200   'private' => 'PRIVATE',
201   'changed' => 'CHANGED TEST',
202   'changed' => 'CHANGED CHILD',
203))
204{"addedHooks":"ADDEDHOOKS","virtual":"VIRTUAL","backed":"BACKED"}
205array(5) {
206  ["addedHooks"]=>
207  string(10) "addedHooks"
208  ["backed"]=>
209  string(6) "backed"
210  ["%0Test%0private"]=>
211  string(7) "private"
212  ["%0Test%0changed"]=>
213  string(12) "changed Test"
214  ["%0Child%0changed"]=>
215  string(13) "changed Child"
216}
217
218
219Child::dumpChild():
220object(Child)#%d (5) {
221  ["addedHooks"]=>
222  string(10) "addedHooks"
223  ["backed"]=>
224  string(6) "backed"
225  ["private":"Test":private]=>
226  string(7) "private"
227  ["changed":"Test":private]=>
228  string(12) "changed Test"
229  ["changed":"Child":private]=>
230  string(13) "changed Child"
231}
232array(4) {
233  ["addedHooks"]=>
234  string(10) "ADDEDHOOKS"
235  ["virtual"]=>
236  string(7) "VIRTUAL"
237  ["backed"]=>
238  string(6) "BACKED"
239  ["changed"]=>
240  string(13) "CHANGED CHILD"
241}
242\Child::__set_state(array(
243   'addedHooks' => 'ADDEDHOOKS',
244   'virtual' => 'VIRTUAL',
245   'backed' => 'BACKED',
246   'private' => 'PRIVATE',
247   'changed' => 'CHANGED TEST',
248   'changed' => 'CHANGED CHILD',
249))
250{"addedHooks":"ADDEDHOOKS","virtual":"VIRTUAL","backed":"BACKED"}
251array(5) {
252  ["addedHooks"]=>
253  string(10) "addedHooks"
254  ["backed"]=>
255  string(6) "backed"
256  ["%0Test%0private"]=>
257  string(7) "private"
258  ["%0Test%0changed"]=>
259  string(12) "changed Test"
260  ["%0Child%0changed"]=>
261  string(13) "changed Child"
262}
263