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 = NULL;
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 variable $file_handle in %s on line %d
75
76Warning: Undefined variable $file_handle in %s on line %d
77After 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:"%0members%0var_private";i:10;s:16:"%0*%0var_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;}"
78After Unserialization => object(C)#%d (8) {
79  ["a"]=>
80  int(10)
81  ["b"]=>
82  string(6) "string"
83  ["c"]=>
84  bool(true)
85  ["d"]=>
86  float(-2.344440000000000079438677857979200780391693115234375)
87  ["e"]=>
88  array(7) {
89    [0]=>
90    int(1)
91    [1]=>
92    float(2.220000000000000195399252334027551114559173583984375)
93    [2]=>
94    string(6) "string"
95    [3]=>
96    bool(true)
97    [4]=>
98    array(0) {
99    }
100    [5]=>
101    object(members)#%d (3) {
102      ["var_private":"members":private]=>
103      int(10)
104      ["var_protected":protected]=>
105      string(6) "string"
106      ["var_public"]=>
107      array(3) {
108        [0]=>
109        float(-100.1230000000000046611603465862572193145751953125)
110        [1]=>
111        string(6) "string"
112        [2]=>
113        bool(true)
114      }
115    }
116    [6]=>
117    NULL
118  }
119  ["f"]=>
120  object(nomembers)#%d (0) {
121  }
122  ["g"]=>
123  NULL
124  ["h"]=>
125  NULL
126}
127After 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;}"
128After Unserialization => object(D)#%d (8) {
129  ["a"]=>
130  int(1)
131  ["b"]=>
132  int(2)
133  ["c"]=>
134  int(3333)
135  ["d"]=>
136  int(444444)
137  ["e"]=>
138  NULL
139  ["f"]=>
140  NULL
141  ["g"]=>
142  NULL
143  ["h"]=>
144  NULL
145}
146After 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;}"
147After Unserialization => object(D)#%d (8) {
148  ["a"]=>
149  float(0.5)
150  ["b"]=>
151  float(0.005000000000000000104083408558608425664715468883514404296875)
152  ["c"]=>
153  float(-1.3449999999999999733546474089962430298328399658203125)
154  ["d"]=>
155  float(1000500)
156  ["e"]=>
157  NULL
158  ["f"]=>
159  NULL
160  ["g"]=>
161  NULL
162  ["h"]=>
163  NULL
164}
165After 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;}"
166After Unserialization => object(D)#%d (8) {
167  ["a"]=>
168  bool(true)
169  ["b"]=>
170  bool(true)
171  ["c"]=>
172  bool(false)
173  ["d"]=>
174  bool(false)
175  ["e"]=>
176  NULL
177  ["f"]=>
178  NULL
179  ["g"]=>
180  NULL
181  ["h"]=>
182  NULL
183}
184After 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;}"
185After Unserialization => object(D)#%d (8) {
186  ["a"]=>
187  string(1) "a"
188  ["b"]=>
189  string(1) "a"
190  ["c"]=>
191  string(6) "string"
192  ["d"]=>
193  string(6) "string"
194  ["e"]=>
195  NULL
196  ["f"]=>
197  NULL
198  ["g"]=>
199  NULL
200  ["h"]=>
201  NULL
202}
203After 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;}"
204After Unserialization => object(D)#%d (8) {
205  ["a"]=>
206  array(0) {
207  }
208  ["b"]=>
209  array(5) {
210    [0]=>
211    int(1)
212    [1]=>
213    float(2.221999999999999975131004248396493494510650634765625)
214    [2]=>
215    bool(true)
216    [3]=>
217    bool(false)
218    [4]=>
219    string(6) "string"
220  }
221  ["c"]=>
222  array(4) {
223    [0]=>
224    object(nomembers)#%d (0) {
225    }
226    [1]=>
227    NULL
228    [2]=>
229    NULL
230    [3]=>
231    string(0) ""
232  }
233  ["d"]=>
234  array(1) {
235    [0]=>
236    array(4) {
237      [0]=>
238      int(1)
239      [1]=>
240      int(2)
241      [2]=>
242      int(3)
243      [3]=>
244      array(0) {
245      }
246    }
247  }
248  ["e"]=>
249  NULL
250  ["f"]=>
251  NULL
252  ["g"]=>
253  NULL
254  ["h"]=>
255  NULL
256}
257After 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:"%0";s:1:"e";N;s:1:"f";N;s:1:"g";N;s:1:"h";N;}"
258After Unserialization => object(D)#%d (8) {
259  ["a"]=>
260  NULL
261  ["b"]=>
262  NULL
263  ["c"]=>
264  string(0) ""
265  ["d"]=>
266  string(1) "%0"
267  ["e"]=>
268  NULL
269  ["f"]=>
270  NULL
271  ["g"]=>
272  NULL
273  ["h"]=>
274  NULL
275}
276After Serialization => string(303) "O:1:"D":8:{s:1:"a";O:7:"members":3:{s:20:"%0members%0var_private";i:10;s:16:"%0*%0var_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;}"
277After Unserialization => object(D)#%d (8) {
278  ["a"]=>
279  object(members)#%d (3) {
280    ["var_private":"members":private]=>
281    int(10)
282    ["var_protected":protected]=>
283    string(6) "string"
284    ["var_public"]=>
285    array(3) {
286      [0]=>
287      float(-100.1230000000000046611603465862572193145751953125)
288      [1]=>
289      string(6) "string"
290      [2]=>
291      bool(true)
292    }
293  }
294  ["b"]=>
295  object(nomembers)#%d (0) {
296  }
297  ["c"]=>
298  NULL
299  ["d"]=>
300  NULL
301  ["e"]=>
302  NULL
303  ["f"]=>
304  NULL
305  ["g"]=>
306  NULL
307  ["h"]=>
308  NULL
309}
310
311Done
312