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 ["APriv":"A":private]=> 101 string(7) "A.APriv" 102 ["AProt":protected]=> 103 string(7) "A.AProt" 104 ["APub"]=> 105 string(6) "A.APub" 106 ["BPriv":"B":private]=> 107 string(7) "B.BPriv" 108 ["BProt":protected]=> 109 string(7) "B.BProt" 110 ["BPub"]=> 111 string(6) "B.BPub" 112} 113Serialized form: 114string(184) "O:1:"B":6:{s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"A.AProt";s:4:"APub";s:6:"A.APub";s:8:"\0B\0BPriv";s:7:"B.BPriv";s:8:"\0*\0BProt";s:7:"B.BProt";s:4:"BPub";s:6:"B.BPub";}" 115Unserialized: 116object(B)#%d (6) { 117 ["APriv":"A":private]=> 118 string(7) "A.APriv" 119 ["AProt":protected]=> 120 string(7) "A.AProt" 121 ["APub"]=> 122 string(6) "A.APub" 123 ["BPriv":"B":private]=> 124 string(7) "B.BPriv" 125 ["BProt":protected]=> 126 string(7) "B.BProt" 127 ["BPub"]=> 128 string(6) "B.BPub" 129} 130Sanity check: bool(true) 131 132 133-- Test instance of C -- 134 135 136Before serialization: 137object(C)#%d (10) { 138 ["APriv":"A":private]=> 139 string(7) "A.APriv" 140 ["AProt":protected]=> 141 string(7) "C.AProt" 142 ["APub"]=> 143 string(6) "C.APub" 144 ["BPriv":"B":private]=> 145 string(7) "B.BPriv" 146 ["BProt":protected]=> 147 string(7) "B.BProt" 148 ["BPub"]=> 149 string(6) "B.BPub" 150 ["APriv":"C":private]=> 151 string(7) "C.APriv" 152 ["CPriv":"C":private]=> 153 string(7) "C.CPriv" 154 ["CProt":protected]=> 155 string(7) "C.BProt" 156 ["CPub"]=> 157 string(6) "C.CPub" 158} 159Serialized form: 160string(302) "O:1:"C":10:{s:8:"\0A\0APriv";s:7:"A.APriv";s:8:"\0*\0AProt";s:7:"C.AProt";s:4:"APub";s:6:"C.APub";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:"\0C\0APriv";s:7:"C.APriv";s:8:"\0C\0CPriv";s:7:"C.CPriv";s:8:"\0*\0CProt";s:7:"C.BProt";s:4:"CPub";s:6:"C.CPub";}" 161Unserialized: 162object(C)#%d (10) { 163 ["APriv":"A":private]=> 164 string(7) "A.APriv" 165 ["AProt":protected]=> 166 string(7) "C.AProt" 167 ["APub"]=> 168 string(6) "C.APub" 169 ["BPriv":"B":private]=> 170 string(7) "B.BPriv" 171 ["BProt":protected]=> 172 string(7) "B.BProt" 173 ["BPub"]=> 174 string(6) "B.BPub" 175 ["APriv":"C":private]=> 176 string(7) "C.APriv" 177 ["CPriv":"C":private]=> 178 string(7) "C.CPriv" 179 ["CProt":protected]=> 180 string(7) "C.BProt" 181 ["CPub"]=> 182 string(6) "C.CPub" 183} 184Sanity check: bool(true) 185Done 186