Reply to Re: can i have an array as a class variable?

Your name:

Reply:


Posted by Kimmo Laine on 09/07/06 08:36

"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)

[Back to original 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация