1--TEST-- 2Test serialize() & unserialize() functions: objects (variations) 3--INI-- 4serialize_precision=100 5--FILE-- 6<?php 7/* Prototype : proto string serialize(mixed variable) 8 * Description: Returns a string representation of variable (which can later be unserialized) 9 * Source code: ext/standard/var.c 10 * Alias to functions: 11 */ 12/* Prototype : proto mixed unserialize(string variable_representation) 13 * Description: Takes a string representation of variable and recreates it 14 * Source code: ext/standard/var.c 15 * Alias to functions: 16 */ 17 18echo "\n--- Testing Variations in objects ---\n"; 19 20class members 21{ 22 private $var_private = 10; 23 protected $var_protected = "string"; 24 public $var_public = array(-100.123, "string", TRUE); 25} 26 27class nomembers { } 28 29class C { 30 var $a, $b, $c, $d, $e, $f, $g, $h; 31 function __construct() { 32 $this->a = 10; 33 $this->b = "string"; 34 $this->c = TRUE; 35 $this->d = -2.34444; 36 $this->e = array(1, 2.22, "string", TRUE, array(), 37 new members(), null); 38 $this->f = new nomembers(); 39 $this->g = $GLOBALS['file_handle']; 40 $this->h = NULL; 41 } 42} 43 44class D extends C { 45 function __construct( $w, $x, $y, $z ) { 46 $this->a = $w; 47 $this->b = $x; 48 $this->c = $y; 49 $this->d = $z; 50 } 51} 52 53$variation_obj_arr = array( 54 new C(), 55 new D( 1, 2, 3333, 444444 ), 56 new D( .5, 0.005, -1.345, 10.005e5 ), 57 new D( TRUE, true, FALSE, false ), 58 new D( "a", 'a', "string", 'string' ), 59 new D( array(), 60 array(1, 2.222, TRUE, FALSE, "string"), 61 array(new nomembers(), $file_handle, NULL, ""), 62 array(array(1,2,3,array())) 63 ), 64 new D( NULL, null, "", "\0" ), 65 new D( new members, new nomembers, $file_handle, NULL), 66); 67 68/* Testing serialization on all the objects through loop */ 69foreach( $variation_obj_arr as $object) { 70 71 echo "After Serialization => "; 72 $serialize_data = serialize( $object ); 73 var_dump( $serialize_data ); 74 75 echo "After Unserialization => "; 76 $unserialize_data = unserialize( $serialize_data ); 77 var_dump( $unserialize_data ); 78} 79 80echo "\nDone"; 81?> 82--EXPECTF-- 83--- Testing Variations in objects --- 84 85Notice: Undefined index: file_handle in %s on line 34 86 87Notice: Undefined variable: file_handle in %s on line 56 88 89Notice: Undefined variable: file_handle in %s on line 60 90After Serialization => string(493) "O:1:"C":8:{s:1:"a";i:10;s:1:"b";s:6:"string";s:1:"c";b:1;s:1:"d";d:-2.344440000000000079438677857979200780391693115234375;s:1:"e";a:7:{i:0;i:1;i:1;d:2.220000000000000195399252334027551114559173583984375;i:2;s:6:"string";i:3;b:1;i:4;a:0:{}i:5;O:7:"members":3:{s:20:"membersvar_private";i:10;s:16:"*var_protected";s:6:"string";s:10:"var_public";a:3:{i:0;d:-100.1230000000000046611603465862572193145751953125;i:1;s:6:"string";i:2;b:1;}}i:6;N;}s:1:"f";O:9:"nomembers":0:{}s:1:"g";N;s:1:"h";N;}" 91After Unserialization => object(C)#%d (8) { 92 ["a"]=> 93 int(10) 94 ["b"]=> 95 string(6) "string" 96 ["c"]=> 97 bool(true) 98 ["d"]=> 99 float(-2.34444) 100 ["e"]=> 101 array(7) { 102 [0]=> 103 int(1) 104 [1]=> 105 float(2.22) 106 [2]=> 107 string(6) "string" 108 [3]=> 109 bool(true) 110 [4]=> 111 array(0) { 112 } 113 [5]=> 114 object(members)#%d (3) { 115 ["var_private":"members":private]=> 116 int(10) 117 ["var_protected":protected]=> 118 string(6) "string" 119 ["var_public"]=> 120 array(3) { 121 [0]=> 122 float(-100.123) 123 [1]=> 124 string(6) "string" 125 [2]=> 126 bool(true) 127 } 128 } 129 [6]=> 130 NULL 131 } 132 ["f"]=> 133 object(nomembers)#%d (0) { 134 } 135 ["g"]=> 136 NULL 137 ["h"]=> 138 NULL 139} 140After Serialization => string(108) "O:1:"D":8:{s:1:"a";i:1;s:1:"b";i:2;s:1:"c";i:3333;s:1:"d";i:444444;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 141After Unserialization => object(D)#%d (8) { 142 ["a"]=> 143 int(1) 144 ["b"]=> 145 int(2) 146 ["c"]=> 147 int(3333) 148 ["d"]=> 149 int(444444) 150 ["e"]=> 151 NULL 152 ["f"]=> 153 NULL 154 ["g"]=> 155 NULL 156 ["h"]=> 157 NULL 158} 159After Serialization => string(223) "O:1:"D":8:{s:1:"a";d:0.5;s:1:"b";d:0.005000000000000000104083408558608425664715468883514404296875;s:1:"c";d:-1.3449999999999999733546474089962430298328399658203125;s:1:"d";d:1000500;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 160After Unserialization => object(D)#%d (8) { 161 ["a"]=> 162 float(0.5) 163 ["b"]=> 164 float(0.005) 165 ["c"]=> 166 float(-1.345) 167 ["d"]=> 168 float(1000500) 169 ["e"]=> 170 NULL 171 ["f"]=> 172 NULL 173 ["g"]=> 174 NULL 175 ["h"]=> 176 NULL 177} 178After Serialization => string(100) "O:1:"D":8:{s:1:"a";b:1;s:1:"b";b:1;s:1:"c";b:0;s:1:"d";b:0;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 179After Unserialization => object(D)#%d (8) { 180 ["a"]=> 181 bool(true) 182 ["b"]=> 183 bool(true) 184 ["c"]=> 185 bool(false) 186 ["d"]=> 187 bool(false) 188 ["e"]=> 189 NULL 190 ["f"]=> 191 NULL 192 ["g"]=> 193 NULL 194 ["h"]=> 195 NULL 196} 197After Serialization => string(126) "O:1:"D":8:{s:1:"a";s:1:"a";s:1:"b";s:1:"a";s:1:"c";s:6:"string";s:1:"d";s:6:"string";s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 198After Unserialization => object(D)#%d (8) { 199 ["a"]=> 200 string(1) "a" 201 ["b"]=> 202 string(1) "a" 203 ["c"]=> 204 string(6) "string" 205 ["d"]=> 206 string(6) "string" 207 ["e"]=> 208 NULL 209 ["f"]=> 210 NULL 211 ["g"]=> 212 NULL 213 ["h"]=> 214 NULL 215} 216After Serialization => string(300) "O:1:"D":8:{s:1:"a";a:0:{}s:1:"b";a:5:{i:0;i:1;i:1;d:2.221999999999999975131004248396493494510650634765625;i:2;b:1;i:3;b:0;i:4;s:6:"string";}s:1:"c";a:4:{i:0;O:9:"nomembers":0:{}i:1;N;i:2;N;i:3;s:0:"";}s:1:"d";a:1:{i:0;a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;a:0:{}}}s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 217After Unserialization => object(D)#%d (8) { 218 ["a"]=> 219 array(0) { 220 } 221 ["b"]=> 222 array(5) { 223 [0]=> 224 int(1) 225 [1]=> 226 float(2.222) 227 [2]=> 228 bool(true) 229 [3]=> 230 bool(false) 231 [4]=> 232 string(6) "string" 233 } 234 ["c"]=> 235 array(4) { 236 [0]=> 237 object(nomembers)#%d (0) { 238 } 239 [1]=> 240 NULL 241 [2]=> 242 NULL 243 [3]=> 244 string(0) "" 245 } 246 ["d"]=> 247 array(1) { 248 [0]=> 249 array(4) { 250 [0]=> 251 int(1) 252 [1]=> 253 int(2) 254 [2]=> 255 int(3) 256 [3]=> 257 array(0) { 258 } 259 } 260 } 261 ["e"]=> 262 NULL 263 ["f"]=> 264 NULL 265 ["g"]=> 266 NULL 267 ["h"]=> 268 NULL 269} 270After Serialization => string(103) "O:1:"D":8:{s:1:"a";N;s:1:"b";N;s:1:"c";s:0:"";s:1:"d";s:1:"";s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 271After Unserialization => object(D)#%d (8) { 272 ["a"]=> 273 NULL 274 ["b"]=> 275 NULL 276 ["c"]=> 277 string(0) "" 278 ["d"]=> 279 string(1) "" 280 ["e"]=> 281 NULL 282 ["f"]=> 283 NULL 284 ["g"]=> 285 NULL 286 ["h"]=> 287 NULL 288} 289After Serialization => string(303) "O:1:"D":8:{s:1:"a";O:7:"members":3:{s:20:"membersvar_private";i:10;s:16:"*var_protected";s:6:"string";s:10:"var_public";a:3:{i:0;d:-100.1230000000000046611603465862572193145751953125;i:1;s:6:"string";i:2;b:1;}}s:1:"b";O:9:"nomembers":0:{}s:1:"c";N;s:1:"d";N;s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}" 290After Unserialization => object(D)#%d (8) { 291 ["a"]=> 292 object(members)#%d (3) { 293 ["var_private":"members":private]=> 294 int(10) 295 ["var_protected":protected]=> 296 string(6) "string" 297 ["var_public"]=> 298 array(3) { 299 [0]=> 300 float(-100.123) 301 [1]=> 302 string(6) "string" 303 [2]=> 304 bool(true) 305 } 306 } 307 ["b"]=> 308 object(nomembers)#%d (0) { 309 } 310 ["c"]=> 311 NULL 312 ["d"]=> 313 NULL 314 ["e"]=> 315 NULL 316 ["f"]=> 317 NULL 318 ["g"]=> 319 NULL 320 ["h"]=> 321 NULL 322} 323 324Done 325