You are here: Re: can i have an array as a class variable? « PHP Programming Language « IT news, forums, messages
Re: can i have an array as a class variable?

Posted by nephish on 09/07/06 12:07

Kimmo Laine wrote:
> "nephish" <nephish@gmail.com> wrote in message
> news:1157550802.659286.20280@b28g2000cwb.googlegroups.com...
> > OK, i have a new question now.
> > can i set a class object in a session variable ?
> >
> > like this:
> >
> > class Person
> > {
> > function Person($name)
> > {
> > $this->name = $name;
> > }
> > }
> >
> > $frank = new Person;
> > $_SESSION['name'] = $frank;
> >
> > or is this just too much ?
> > }
>
> Not just like that, you must first convert the object to a storeable format,
> it's called serializing. There is a function called serialize() and it's
> compliment function unserialize(). When you store the object to session, you
> serialize it first. then when you need to revert it back from the session,
> you unserialize it. And also, the class definition must be available on each
> page where the object is accessed. If it is missing, the object can't be
> unserialized.
>
> on page1.php:
> $_SESSION['name'] = serialize($frank);
>
> on page2.php:
> $frank = unserialize($_SESSION['name']);
>
> --
> "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
> http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
> spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)

Well, thanks ! this could make my sessions and keeping track of state a
whole lot easier. I had looked at serialize, but i thought that it had
to be set in a database. I didn't know it was that easy.

thanks a lot.

shawn

 

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

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