Help with Serializing Objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #1

    Help with Serializing Objects

    Hi,

    I'm currently working on a new system and have built a number of objects for controlling data access user properties etc. I want to pass the object between pages.

    The site works in the following way:
    Login.php - accesscheck.php - valid credentials? - N - login.php
    Login.php - accesscheck.php - valid credentials? - Y - mainpage.php

    Mainpage.php will be the only page for the display of data as using AJAX I will alter this page.

    When the credentials are passed to accesscheck the dataobect and userobject are instantiated and I would like to pass these on to mainpage.php.

    I have read that serialization is the way to do this but I have also read a few things about this that worry me a bit.

    For instance I have read that you should not serialize an object if it references itself. My objects do that using $this->propertyname .

    Also the user object has an instance of the dataobject on it. So perhaps I only need to pass one of them over I don't know.

    I have read a lot about this and ended up confused. So I thought I would ask for some friendly advice.

    Thanks in advacne
    nathj
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Nathj.

    There is nothing inherently bad about serializing objects. The only bad stuff comes into play when the serialized object is accessible from the client side.

    The solution is to simply store the instance in the $_SESSION. PHP will automatically serialize each object at the end of script execution and unserialize each object when you call session_start() .

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by pbmods
      Heya, Nathj.

      There is nothing inherently bad about serializing objects. The only bad stuff comes into play when the serialized object is accessible from the client side.

      The solution is to simply store the instance in the $_SESSION. PHP will automatically serialize each object at the end of script execution and unserialize each object when you call session_start() .
      Thanks for the advice. I'll make sure that all my serialized objects are stored in the $_SESSION.

      Cheers
      nathj

      Comment

      Working...