File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / serialize / bug36424.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:45 2012 UTC (12 years, 5 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, HEAD
php 5.4.3+patches

--TEST--
Bug #36424 - Serializable interface breaks object references
--FILE--
<?php

echo "-TEST\n";

class a implements Serializable {
    function serialize() {
        return serialize(get_object_vars($this));
    }
    function unserialize($s) {
        foreach (unserialize($s) as $p=>$v) {
            $this->$p=$v;
        }
    }
}
class b extends a {}
class c extends b {}

$c = new c;
$c->a = new a;
$c->a->b = new b;
$c->a->b->c = $c;
$c->a->c = $c;
$c->a->b->a = $c->a;
$c->a->a = $c->a;

$s = serialize($c);
printf("%s\n", $s);

$d = unserialize($s);

var_dump(
    $d === $d->a->b->c,
    $d->a->a === $d->a,
    $d->a->b->a === $d->a,
    $d->a->c === $d
);

print_r($d);

echo "Done\n";

?>
--EXPECTF--
%aTEST
C: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;}}}}
bool(true)
bool(true)
bool(true)
bool(true)
c Object
(
    [a] => a Object
        (
            [b] => b Object
                (
                    [c] => c Object
 *RECURSION*
                    [a] => a Object
 *RECURSION*
                )

            [c] => c Object
 *RECURSION*
            [a] => a Object
 *RECURSION*
        )

)
Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>