serializing objects that hold other objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Perttu Pulkkinen

    serializing objects that hold other objects

    Hi!
    I have been thinking (not testing yet) what happens if I have something
    like:

    class a
    { ...}
    class b
    { var a_item = new a(); ...}

    $john = new b();
    $ser = serialize($john );

    Is the definition of class a also serialized with john and definition of
    class b?

    - Perttu Pulkkinen, Finland


  • Jonathan Moss

    #2
    Re: serializing objects that hold other objects


    "Perttu Pulkkinen" <perttu.pulkkin en@co.jyu.fi> wrote in message
    news:dqoSb.54$K 6.53@read3.inet .fi...[color=blue]
    > Hi!
    > I have been thinking (not testing yet) what happens if I have something
    > like:
    >
    > class a
    > { ...}
    > class b
    > { var a_item = new a(); ...}
    >
    > $john = new b();
    > $ser = serialize($john );
    >
    > Is the definition of class a also serialized with john and definition of
    > class b?
    >
    > - Perttu Pulkkinen, Finland[/color]

    Yes, class a will be serialized as a property of class b (John)

    regards,
    Jon


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.569 / Virus Database: 360 - Release Date: 26/01/2004


    Comment

    • Chung Leong

      #3
      Re: serializing objects that hold other objects

      No, the class definition is not stored. If you unserialize the string before
      the class is defined the object will become of the class
      __PHP_Incomplet e_Class.

      Uzytkownik "Perttu Pulkkinen" <perttu.pulkkin en@co.jyu.fi> napisal w
      wiadomosci news:dqoSb.54$K 6.53@read3.inet .fi...[color=blue]
      > Hi!
      > I have been thinking (not testing yet) what happens if I have something
      > like:
      >
      > class a
      > { ...}
      > class b
      > { var a_item = new a(); ...}
      >
      > $john = new b();
      > $ser = serialize($john );
      >
      > Is the definition of class a also serialized with john and definition of
      > class b?
      >
      > - Perttu Pulkkinen, Finland
      >
      >[/color]


      Comment

      • Rahul Anand

        #4
        Re: serializing objects that hold other objects

        "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<GJSdnd_on J1Bd4fd4p2dnA@c omcast.com>...[color=blue]
        > No, the class definition is not stored. If you unserialize the string before
        > the class is defined the object will become of the class
        > __PHP_Incomplet e_Class.
        >
        > Uzytkownik "Perttu Pulkkinen" <perttu.pulkkin en@co.jyu.fi> napisal w
        > wiadomosci news:dqoSb.54$K 6.53@read3.inet .fi...[color=green]
        > > Hi!
        > > I have been thinking (not testing yet) what happens if I have something
        > > like:
        > >
        > > class a
        > > { ...}
        > > class b
        > > { var a_item = new a(); ...}
        > >
        > > $john = new b();
        > > $ser = serialize($john );
        > >
        > > Is the definition of class a also serialized with john and definition of
        > > class b?
        > >
        > > - Perttu Pulkkinen, Finland
        > >
        > >[/color][/color]

        You are always required to define your class before serialize or
        unserialize operation.
        If defined you can serialize and unserialize all objects (even with
        child objects). But you can not properly serialize and unserialize a
        class with some php resource as its member.

        Hope it will help.

        --
        Rahul Anand

        Comment

        Working...