Can someone please help me!!!! i am simply trying to pass an object between two PHP pages. I have instantiated a controller class ( $control = new Controller() ) and just wish to pass this object ($control) to another page so it can be used there. Is this possible? Would I try and pass it through the URL or through a hidden field or is the some other way?

    you can concat the variables of the object into a string, submit it using a hidden form field, explode the vars and create a new object in the target script....?!?!

    or try using sessions... like that:

    <?
    	class myClass {
    	  var $var1;
    	  var $var2;
    	  function myClass ($var1=0, $var2=0)
    	  {
    	    $this->var1 = $var1;
    	    $this->var2 = $var2;
    	  }
    	  function getSum()
    	  {
    	    return ($this->var1 + $this->var2);
    	  }
    	}
    
    $obj = new myClass(3,5);	
    session_start();
    session_register("obj");
    
    echo "<a href=\"nextPage.php\">go</a>";
    ?>
    

    The nextPage.php could look like this:

    <?
    	class myClass {
    	  var $var1;
    	  var $var2;
    	  function myClass ($var1=0, $var2=0)
    	  {
    	    $this->var1 = $var1;
    	    $this->var2 = $var2;
    	  }
    	  function getSum()
    	  {
    	    return ($this->var1 + $this->var2);
    	  }
    	}
    
    session_start();
    echo $_SESSION['obj']->getSum();	
    ?>
    

      Thank-you SO much! That worked a treat! I am still wondering though if there are any other ways without using cookies or sessions. I have tried serializing but am having difficulties parsing the values back into the correct object type. I think my main problem is that I am trying to pass a Control reference around as opposed to Entity class values. Anyhow, thanks for the time you took to reply, I really appreciate it. m@

        Write a Reply...