You are here: Re: Passing objects from one page to another « All PHP « IT news, forums, messages
Re: Passing objects from one page to another

Posted by Marcel on 11/08/06 15:18

"ZeldorBlat" <zeldorblat@gmail.com> schreef in bericht
news:1162998447.934912.233680@i42g2000cwa.googlegroups.com...
>
> Marcel wrote:
>> 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();
>
> Difficult to say since you haven't told us what doesn't work. As in
> you get some error that you can't unserialize it? Or no error at all
> (as in your error reporting is turned off)?
>
> My guess would be that
> $p = unserialize(urldecode($_GET['data']));
> should really be just
> $p = unserialize($_GET['data']);
>
> But I didn't test it.
>

Yes you are right, the errorcode i am getting is:

Fatal error: Call to a member function getName() on a non-object in
D:\public_html\person2.php on line 7

Regards,

Marcel

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация