1--TEST-- 2Bug #64146 (serialize incorrectly saving objects when they are cloned) 3--FILE-- 4<?php 5 6class A 7{ 8 public $a = array(); 9 10 public function __construct() 11 { 12 $this->a[] = new B(1); 13 $this->a[] = new B(2); 14 } 15} 16 17class B implements Serializable 18{ 19 public $b; 20 21 public function __construct($c) 22 { 23 $this->b = new C($c); 24 } 25 26 public function serialize() 27 { 28 return serialize(clone $this->b); 29 } 30 31 public function unserialize($data) 32 { 33 $this->b = unserialize($data); 34 } 35} 36 37class C 38{ 39 public $c; 40 41 public function __construct($c) 42 { 43 $this->c = $c; 44 } 45} 46 47$a = unserialize(serialize(new A())); 48 49print $a->a[0]->b->c . "\n"; 50print $a->a[1]->b->c . "\n"; 51 52?> 53Done 54--EXPECTF-- 55Deprecated: %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 561 572 58Done 59