xref: /PHP-7.4/ext/spl/tests/observer_003.phpt (revision 782352c5)
1--TEST--
2SPL: SplObjectStorage serialization
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
16$storage = new SplObjectStorage();
17
18foreach(array(1,"2","foo",true) as $value)
19{
20     $storage->attach(new TestClass($value));
21}
22
23var_dump(count($storage));
24
25foreach($storage as $object)
26{
27	var_dump($object->test);
28}
29
30var_dump(serialize($storage));
31echo "===UNSERIALIZE===\n";
32
33$storage2 = unserialize(serialize($storage));
34
35var_dump(count($storage2));
36
37foreach($storage2 as $object)
38{
39	var_dump($object->test);
40}
41
42?>
43===DONE===
44<?php exit(0); ?>
45--EXPECTF--
46int(4)
47int(1)
48string(1) "2"
49string(3) "foo"
50bool(true)
51string(%d) "%s"
52===UNSERIALIZE===
53int(4)
54int(1)
55string(1) "2"
56string(3) "foo"
57bool(true)
58===DONE===
59