1--TEST--
2Bug #36424 - Serializable interface breaks object references
3--FILE--
4<?php
5
6echo "-TEST\n";
7
8class a implements Serializable {
9    function serialize() {
10        return serialize(get_object_vars($this));
11    }
12    function unserialize($s) {
13        foreach (unserialize($s) as $p=>$v) {
14            $this->$p=$v;
15        }
16    }
17}
18class b extends a {}
19class c extends b {}
20
21$c = new c;
22$c->a = new a;
23$c->a->b = new b;
24$c->a->b->c = $c;
25$c->a->c = $c;
26$c->a->b->a = $c->a;
27$c->a->a = $c->a;
28
29$s = serialize($c);
30printf("%s\n", $s);
31
32$d = unserialize($s);
33
34var_dump(
35    $d === $d->a->b->c,
36    $d->a->a === $d->a,
37    $d->a->b->a === $d->a,
38    $d->a->c === $d
39);
40
41print_r($d);
42
43echo "Done\n";
44
45?>
46--EXPECTF--
47%aTEST
48C: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;}}}}
49bool(true)
50bool(true)
51bool(true)
52bool(true)
53c Object
54(
55    [a] => a Object
56        (
57            [b] => b Object
58                (
59                    [c] => c Object
60 *RECURSION*
61                    [a] => a Object
62 *RECURSION*
63                )
64
65            [c] => c Object
66 *RECURSION*
67            [a] => a Object
68 *RECURSION*
69        )
70
71)
72Done
73