xref: /PHP-5.3/ext/spl/tests/observer_004.phpt (revision 610c7fbe)
1--TEST--
2SPL: SplObjectStorage serialization & overloading
3--FILE--
4<?php
5
6class TestClass
7{
8	public $test = 25;
9
10	public function __construct($test = 42)
11	{
12		$this->test = $test;
13	}
14}
15
16class MyStorage extends SplObjectStorage
17{
18	public $bla = 25;
19
20	public function __construct($bla = 26)
21	{
22		$this->bla = $bla;
23	}
24}
25
26$storage = new MyStorage();
27
28foreach(array(1,2) as $value)
29{
30     $storage->attach(new TestClass($value));
31}
32
33var_dump(count($storage));
34
35foreach($storage as $object)
36{
37	var_dump($object->test);
38}
39
40var_dump($storage);
41
42var_dump(serialize($storage));
43echo "===UNSERIALIZE===\n";
44
45$storage2 = unserialize(serialize($storage));
46
47var_dump(count($storage2));
48
49foreach($storage2 as $object)
50{
51	var_dump($object->test);
52}
53
54var_dump($storage2);
55
56?>
57===DONE===
58<?php exit(0); ?>
59--EXPECTF--
60int(2)
61int(1)
62int(2)
63object(MyStorage)#%d (2) {
64  ["bla"]=>
65  int(26)
66  ["storage":"SplObjectStorage":private]=>
67  array(2) {
68    ["%s"]=>
69    array(2) {
70      ["obj"]=>
71      object(TestClass)#%d (1) {
72        ["test"]=>
73        int(1)
74      }
75      ["inf"]=>
76      NULL
77    }
78    ["%s"]=>
79    array(2) {
80      ["obj"]=>
81      object(TestClass)#%d (1) {
82        ["test"]=>
83        int(2)
84      }
85      ["inf"]=>
86      NULL
87    }
88  }
89}
90string(%d) "%s"
91===UNSERIALIZE===
92int(2)
93int(1)
94int(2)
95object(MyStorage)#%d (2) {
96  ["bla"]=>
97  int(26)
98  ["storage":"SplObjectStorage":private]=>
99  array(2) {
100    ["%s"]=>
101    array(2) {
102      ["obj"]=>
103      object(TestClass)#%d (1) {
104        ["test"]=>
105        int(1)
106      }
107      ["inf"]=>
108      NULL
109    }
110    ["%s"]=>
111    array(2) {
112      ["obj"]=>
113      object(TestClass)#%d (1) {
114        ["test"]=>
115        int(2)
116      }
117      ["inf"]=>
118      NULL
119    }
120  }
121}
122===DONE===
123