Re: Newbie: nested include and object in session

From: Date: Thu, 21 Nov 2002 08:31:49 +0000
Subject: Re: Newbie: nested include and object in session
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-125386@lists.php.net to get a copy of this message
At 04:30 21.11.2002, Michael Wai said: --------------------[snip]-------------------- >Hi everyone, I'm a newbie on PHP and MySQL. I've two questions that want to >get some help. > >1. How to solve the problem of nested include? That's mean A include B and B >include C. Just do it, it works perfectly. >2. Can I save the object in session? Yes: session_start(); $_SESSION['myobject'] =& $myobject; What you need to observe is that the class MUST be declared BEFORE the session is reloaded: // won't work session_start(); class A { function A() {} } if (!$a) { $a = new A(); $_SESSION['a'] =& $a; } Here your session is started _before_ the class gets declared. This works for the first time, but when reloading the session object $a will be reconstructed without the class definition readily available, so PHP will default to a standard class. The next example will work, though: class A { function A() {} } session_start(); if (!$a) { $a = new A(); $_SESSION['a'] =& $a; } As you can see the class decl is given _before_ the session is started. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#125386) next »