Serialisation of References 
Author Message
 Serialisation of References

I have a structure with backreferenced objects. When I try to
serialize it, php hangs for minutes and finaly is stopped by time out.

I think the problem is, that references re serialized by value and so
the serialisation mechanism enters an infinite recursive loop.

Is there any way to circumvent this (explicit referencing doesn't
work) ?

Shouln't this be solved in Php5 ?

Example:

    class Foo
    {
        private $element;

        function __construct()
        {
            $this->element = new Element($this);
        }
    }

    class Element
    {
        private $parent;

        function __construct($parent)
        {
            $this->parent = & $parent;
        }
    }

    echo serialize( new Foo() );



Fri, 20 May 2005 23:20:10 GMT  
 Serialisation of References

Quote:
> I have a structure with backreferenced objects. When I try to
> serialize it, php hangs for minutes and finaly is stopped by time out.
> I think the problem is, that references re serialized by value and so
> the serialisation mechanism enters an infinite recursive loop.

Yes, this is possible.
The parent serializes the child
The child serializes the parent
-> so on to infinity.

Quote:
> Is there any way to circumvent this (explicit referencing doesn't
> work) ?

Read:
http://www.php.net/manual/en/language.oop.serialization.php
http://www.php.net/manual/en/language.oop.magic-functions.php

You may find a way.

I've not done it my self,
but I can envision how it might be handled ;)

regards,
reggie.



Sat, 21 May 2005 06:59:50 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Serialisation of Eiffel Objects

2. Object Serialisation

3. customised serialisation - sometimes

4. Object serialisation / migration?

5. Reference/Location of ANSI Smalltalk Reference

6. RTX2000 references/Stack computer references

7. Python quick reference reference

8. How do I cast a control reference to a named numeric reference?

9. Call by Reference/Content vs. Using by Reference/Value

10. What are the differences between _weak_ references and "normal" references?

11. HELP **NEED Reference Books** PLEASE!

12. Binary filing and circular references

 

 
Powered by phpBB® Forum Software