Edit report at http://bugs.php.net/bug.php?id=36424&edit=1

 ID:               36424
 User updated by:  mastabog at hotmail dot com
 Reported by:      mastabog at hotmail dot com
 Summary:          Keeping reference info through recursive calls to
                   serialize()
 Status:           Assigned
 Type:             Feature/Change Request
 Package:          Unknown/Other Function
 Operating System: *
 PHP Version:      5.2.14-dev
 Assigned To:      mike

 New Comment:

I still don't understand why this is not seen as a bug. My example shows
that without "implements Serializable" object references are honoured
(as expected) while with "implements Serializable" object references are
broken (which is unexpected).



Seeing you classified this as "feature request" makes me think that
breaking object references was actually intended behaviour or that there
is a way to maintain object references when implementing Serializable.
Can you then please provide the body of the serialize() and
unserialize() methods in class A in the example below that will maintain
object references as expected, i.e. $new_oC->A === $new_oC->B->A?



class A implements Serializable

{

        public function serialize ()

        {

                [...]

        }



        function unserialize($serialized)

        {

                [...]

        }

}



class B extends A

{

        public $A;

}



class C extends A

{

        public $A;

        public $B;

}



$oC = new C();

$oC->A = new A();

$oC->B = new B();

$oC->B->A = $oC->A;



echo $oC->A === $oC->B->A ? "yes" : "no", "\n"; 

$ser = serialize($oC);

$new_oC = unserialize($ser);

echo $new_oC->A === $new_oC->B->A ? "yes" : "no", "\n";


Previous Comments:
------------------------------------------------------------------------
[2010-05-21 11:19:54] m...@php.net

Reclassified as Change Request.



JFYI: http://news.php.net/php.internals/48369

------------------------------------------------------------------------
[2010-05-20 23:21:02] mastabog at hotmail dot com

Why has the status of this been changed to "bogus"?



Are we to understand that the devs regard this as being intended
behaviour, i.e. the Serializable interface breaks object references of
objects implementing it?



The initial reproduce code shows that what was an object reference
before is no longer a reference after unserialization ... this is a bug.
There may be other (better) reproduce codes but the bug is still there.
Why not try and fix it?



Well, I tried but I think I will give up ... it's been 4+ years!

------------------------------------------------------------------------
[2010-05-20 18:31:13] mastabog at hotmail dot com

If you remove "implements Serializable" then it works as expected and
the reproduce code shows that. Revealing the bug was what my report was
about.



It's a bug. It surprises me that nobody wants to fix it after more than
4 years ... apparently it's just me that considers this bug to be
important which is why I still avoid using the Serializable interface
altogether. It's unreliable.

------------------------------------------------------------------------
[2010-05-20 16:09:10] m...@php.net

The reproduce code is wrong.



Your code serializes everything on it's own, as you can see if you
replace



        return $serialized;



with

        $serialized = serialize($serialized);

        printf("serialized %s as '%s'\n", get_class($this),
$serialized);

        return $serialized;





Output:



yes

serialized A as 'a:0:{}'

serialized A as 'a:0:{}'

serialized B as 'a:1:{s:1:"A";C:1:"A":6:{a:0:{}}}'

serialized C as
'a:2:{s:1:"A";C:1:"A":6:{a:0:{}}s:1:"B";C:1:"B":32:{a:1:{s:1:"A";C:1:"A":6:{a:0:{}}}}}'

no

------------------------------------------------------------------------
[2010-03-02 00:31:36] mastabog at hotmail dot com

Hi,



I tested with the latest Linux source snapshot (php5.2-201003011530) and
the bug is still there. I also tested the recently released 5.2.13
release and got the same result. Both Linux and Windows.



Did you run the reproduce code from the first post above and got the
expected result? The bug is definitely there in the snapshot I tested.



I've been avoiding the Serializable interface ever since it got
introduced due to this nasty bug. Could it please be fixed? It's growing
old and strong :)



Cheers

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=36424


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=36424&edit=1

Reply via email to