1--TEST--
2Bug #36424 - Serializable interface breaks object references
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class a implements Serializable {
8    function serialize() {
9        return serialize(get_object_vars($this));
10    }
11    function unserialize($s) {
12        foreach (unserialize($s) as $p=>$v) {
13            $this->$p=$v;
14        }
15    }
16}
17class b extends a {}
18class c extends b {}
19
20$c = new c;
21$c->a = new a;
22$c->a->b = new b;
23$c->a->b->c = $c;
24$c->a->c = $c;
25$c->a->b->a = $c->a;
26$c->a->a = $c->a;
27
28$s = serialize($c);
29printf("%s\n", $s);
30
31$d = unserialize($s);
32
33var_dump(
34    $d === $d->a->b->c,
35    $d->a->a === $d->a,
36    $d->a->b->a === $d->a,
37    $d->a->c === $d
38);
39
40print_r($d);
41
42echo "Done\n";
43
44?>
45--EXPECTF--
46Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
47
48Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
49
50Deprecated: %s implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
51C:1:"c":108:{a:1:{s:1:"a";C:1:"a":81:{a:3:{s:1:"b";C:1:"b":30:{a:2:{s:1:"c";r:1;s:1:"a";r:3;}}s:1:"c";r:1;s:1:"a";r:3;}}}}
52bool(true)
53bool(true)
54bool(true)
55bool(true)
56c Object
57(
58    [a] => a Object
59        (
60            [b] => b Object
61                (
62                    [c] => c Object
63 *RECURSION*
64                    [a] => a Object
65 *RECURSION*
66                )
67
68            [c] => c Object
69 *RECURSION*
70            [a] => a Object
71 *RECURSION*
72        )
73
74)
75Done
76