Object Serialize

Posted on 2008-11-05
Last Modified: 2012-05-05
I want to serialize my object recursively.
How can i complete this job?
ps: i use serialize but it does't serialize Area object in $areaList array of course.

class Design{

	public $areaList=array();

	function __construct(){}

	function __destruct(){}


	function newArea(){

		$area=new Area(null);


		return $area;



class Area{

	public $className="";

	protected $areaId="";

	protected $parentArea=null;

	protected $subAreaCount=0;

	protected $areaObject=null; //Form

	function getHTML($newRow=false){

		if ($newRow==true)



			$className="newArea col";



		$responseStr="<div id='$areaId' class='$className'></div>|";


		return $responseStr;



	function __construct($parentArea){






another page


  $design=new Design();


  $_SESSION["Design"]=serialize($design); //this is just serialize Design object. Not area objects in Design object


Open in new window

Question by:erenpasa
    LVL 11

    Accepted Solution

    You MUST use autoload function So when PHP unserialize Design Objet it will load Area Objet too.

    Put classes in separated files with pattern CLASSNAME.class.php and leave the files on the PHP project path.

    function __autoload($class_name){
       // based on class filename
       require $class_name.".class.php";

    Author Comment

    LVL 11

    Expert Comment

    The solution is for another trouble but seems to work.
    It think that the autoload is better for a simple reason. All data will be in the Server Side so, why transfer a lot of data between Client/Server?
    Whit code above you can put into a general include header and at any time do this

    But, Objects that point to another Object or is extended from another class need that the parent or pointed classes available and the solution is __autoload function (a magic function);

    Its almost a persistance like JAVA do (I said almost).
    Some vars cannot be saved this way (or any other way) like resources (any kind).

    The code below is a snipplet that create the main mecanism to use this kind of persistance.
    The function __autoload above complete the code.

      function serializeVars(){
     // When script ends call this function
      // a general session start 
         // now all saved Vars, including arrays and Objects in the session will be available again

    Open in new window


    Author Comment

    i've applied _autoload. it's okay. thanks

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now