1--TEST--
2Object serialization / unserialization with inherited and hidden properties.
3--FILE--
4<?php
5Class A {
6    private $APriv = "A.APriv";
7    protected $AProt = "A.AProt";
8    public $APub = "A.APub";
9
10    function audit() {
11        return isset($this->APriv, $this->AProt, $this->APub);
12    }
13}
14
15Class B extends A {
16    private $BPriv = "B.BPriv";
17    protected $BProt = "B.BProt";
18    public $BPub = "B.BPub";
19
20    function audit() {
21        return  parent::audit() && isset($this->AProt, $this->APub,
22                     $this->BPriv, $this->BProt, $this->BPub);
23    }
24}
25
26Class C extends B {
27    private $APriv = "C.APriv";
28    protected $AProt = "C.AProt";
29    public $APub = "C.APub";
30
31    private $CPriv = "C.CPriv";
32    protected $CProt = "C.BProt";
33    public $CPub = "C.CPub";
34
35    function audit() {
36        return parent::audit() && isset($this->APriv, $this->AProt, $this->APub,
37                     $this->BProt, $this->BPub,
38                     $this->CPriv, $this->CProt, $this->CPub);
39    }
40}
41
42function prettyPrint($obj) {
43    echo "\n\nBefore serialization:\n";
44    var_dump($obj);
45
46    echo "Serialized form:\n";
47    $ser = serialize($obj);
48    $serPrintable = str_replace("\0", '\0', $ser);
49    var_dump($serPrintable);
50
51    echo "Unserialized:\n";
52    $uobj = unserialize($ser);
53    var_dump($uobj);
54
55    echo "Sanity check: ";
56    var_dump($uobj->audit());
57}
58
59echo "-- Test instance of A --\n";
60prettyPrint(new A);
61echo "\n\n-- Test instance of B --\n";
62prettyPrint(new B);
63echo "\n\n-- Test instance of C --\n";
64prettyPrint(new C);
65
66echo "Done";
67?>
68--EXPECTF--
69-- Test instance of A --
70
71
72Before serialization:
73object(A)#%d (3) {
74  ["APriv":"A":private]=>
75  string(7) "A.APriv"
76  ["AProt":protected]=>
77  string(7) "A.AProt"
78  ["APub"]=>
79  string(6) "A.APub"
80}
81Serialized form:
82string(98) "O:1:"A":3:{s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}"
83Unserialized:
84object(A)#%d (3) {
85  ["APriv":"A":private]=>
86  string(7) "A.APriv"
87  ["AProt":protected]=>
88  string(7) "A.AProt"
89  ["APub"]=>
90  string(6) "A.APub"
91}
92Sanity check: bool(true)
93
94
95-- Test instance of B --
96
97
98Before serialization:
99object(B)#%d (6) {
100  ["BPriv":"B":private]=>
101  string(7) "B.BPriv"
102  ["BProt":protected]=>
103  string(7) "B.BProt"
104  ["BPub"]=>
105  string(6) "B.BPub"
106  ["APriv":"A":private]=>
107  string(7) "A.APriv"
108  ["AProt":protected]=>
109  string(7) "A.AProt"
110  ["APub"]=>
111  string(6) "A.APub"
112}
113Serialized form:
114string(184) "O:1:"B":6:{s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";}"
115Unserialized:
116object(B)#%d (6) {
117  ["BPriv":"B":private]=>
118  string(7) "B.BPriv"
119  ["BProt":protected]=>
120  string(7) "B.BProt"
121  ["BPub"]=>
122  string(6) "B.BPub"
123  ["APriv":"A":private]=>
124  string(7) "A.APriv"
125  ["AProt":protected]=>
126  string(7) "A.AProt"
127  ["APub"]=>
128  string(6) "A.APub"
129}
130Sanity check: bool(true)
131
132
133-- Test instance of C --
134
135
136Before serialization:
137object(C)#%d (10) {
138  ["APriv":"C":private]=>
139  string(7) "C.APriv"
140  ["AProt":protected]=>
141  string(7) "C.AProt"
142  ["APub"]=>
143  string(6) "C.APub"
144  ["CPriv":"C":private]=>
145  string(7) "C.CPriv"
146  ["CProt":protected]=>
147  string(7) "C.BProt"
148  ["CPub"]=>
149  string(6) "C.CPub"
150  ["BPriv":"B":private]=>
151  string(7) "B.BPriv"
152  ["BProt":protected]=>
153  string(7) "B.BProt"
154  ["BPub"]=>
155  string(6) "B.BPub"
156  ["APriv":"A":private]=>
157  string(7) "A.APriv"
158}
159Serialized form:
160string(302) "O:1:"C":10:{s:8:"\0C\0APriv";s:7:"C.APriv";s:8:"\0*\0AProt";s:7:"C.AProt";s:4:"APub";s:6:"C.APub";s:8:"\0C\0CPriv";s:7:"C.CPriv";s:8:"\0*\0CProt";s:7:"C.BProt";s:4:"CPub";s:6:"C.CPub";s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";s:8:"\0A\0APriv";s:7:"A.APriv";}"
161Unserialized:
162object(C)#%d (10) {
163  ["APriv":"C":private]=>
164  string(7) "C.APriv"
165  ["AProt":protected]=>
166  string(7) "C.AProt"
167  ["APub"]=>
168  string(6) "C.APub"
169  ["CPriv":"C":private]=>
170  string(7) "C.CPriv"
171  ["CProt":protected]=>
172  string(7) "C.BProt"
173  ["CPub"]=>
174  string(6) "C.CPub"
175  ["BPriv":"B":private]=>
176  string(7) "B.BPriv"
177  ["BProt":protected]=>
178  string(7) "B.BProt"
179  ["BPub"]=>
180  string(6) "B.BPub"
181  ["APriv":"A":private]=>
182  string(7) "A.APriv"
183}
184Sanity check: bool(true)
185Done
186