xref: /PHP-8.4/ext/spl/tests/observer_003.phpt (revision f8d79582)
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--EXPECTF--
44int(4)
45int(1)
46string(1) "2"
47string(3) "foo"
48bool(true)
49string(%d) "%s"
50===UNSERIALIZE===
51int(4)
52int(1)
53string(1) "2"
54string(3) "foo"
55bool(true)
56