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