| Posted by mannerboy on 11/13/06 06:47 
class.A.php----------------------------------------------
 class A
 {
 var $name;
 function A($name = ''){
 $this->name = $name;
 }
 }
 
 source.php
 ------------------------------
 include("class.A.php");
 $p = new A('arknoah');
 header('Location:dest.php?data='.urlencode(serialize($p)));
 
 
 dest.php
 -------------------------------
 include("class.A.php");
 $q = unserialize(urldecode(stripslashes($_GET['data'])));
 //get_magic_quotes_gpc() = 1
 echo $q->name;exit;
 
 "Marcel 写道:
 "
 > I have a person class adn i want to derive an object of that class on one
 > page and pass that object to a next page but that does not work for me and i
 > do not understand why.
 >
 > Here is de code:
 >
 > class.person.php
 > -----------------------------------
 > class person {
 >
 >  private $_name;
 >
 >  public function setName($name) {
 >
 >   $this->_name = $name;
 >
 >  }
 >
 >  public function getName() {
 >
 >   return $this->_name;
 >
 >  }
 >
 > }
 > --------------------------------------------
 >
 >
 >
 > person1.php // here is the object created
 > -------------------------------------------
 > require_once("class.person.php");
 >
 > $p = new person();
 >
 > $p->setName("Jim");
 >
 > $safep = urlencode(serialize($p));
 >
 > header("Location:person2.php?data=".$safep);
 >
 > exit;
 >
 >
 > person2.php // page where the object is transfered to
 > ---------------------------------------------------
 > require_once("class.person.php");
 >
 > $p = unserialize(urldecode($_GET['data']));
 >
 > echo $p->getName();
  Navigation: [Reply to this message] |