List Info

Thread: note 78680 added to ref.session




note 78680 added to ref.session
user name
2007-10-23 02:01:23
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
----
Server IP: 69.147.83.197
Probable Submitter: 194.231.54.229
----
Manual Page -- http://w
ww.php.net/manual/en/ref.session.php
Edit        -- https://master
.php.net/note/edit/78680
Del: integrated  -- h
ttps://master.php.net/note/delete/78680/integrated
Del: useless     -- http
s://master.php.net/note/delete/78680/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78680/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78680/spam
Del: non-english -- 
https://master.php.net/note/delete/78680/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78680/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78680
Reject      -- https://mast
er.php.net/note/reject/78680
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )