note 78680 deleted from ref.session by nlopess
| From: | nlopess@php.net | Date: | Fri, 26 Oct 2007 19:11:30 +0000 |
| Subject: | note 78680 deleted from ref.session by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-131755@lists.php.net to get a copy of this message | ||
Note Submitter: koch.ro
----
The manual states that:
"Some types of data can not be serialized [...]. It includes [...] objects with circular
references (i.e. objects which passes a reference to itself to another object)."
I wrote a PHPUnit Test[1] that proofs the opposite. Is it possible, that the information above is
outdated and that circular references can be handled by recent PHP versions?
class TestPhpSerializationCircular extends PHPUnit_Framework_TestCase
{
public function testSerializeCircular()
{
$a = new SerializableObject;
$b = new SerializableObject;
$a->ref = $b;
$b->ref = $a;
$serial = serialize( $a );
$this->assertType( 'string', $serial );
$this->assertTrue( strlen( $serial ) > 10 );
}
public function testSerializeCircularPreservesIdentity()
{
$a = new SerializableObject;
$b = new SerializableObject;
$a->ref = $b;
$b->ref = $a;
$serial = serialize( $a );
$after = unserialize( $serial );
$after->ref->ref->property = 'test';
$this->assertSame( $after->property, $after->ref->ref->property );
}
}
[1] http://tinyurl.com/2ktda7