Entry
How do you pass an instance of an object between pages in PHP?
Does the object get passed by value or by reference?
Jun 5th, 2002 04:06
Luc Saffre, Boy Dolphin, Marc Ford,
You must store it in the $_SESSION array.
class A {
//...
}
if (isset($_SESSION['foo'])) {
$a = $_SESSION['foo']
} else {
$a = new A();
$_SESSION['foo'] = a;
}
Be careful : when session_start() will restore this variable, your
script must know the class definition. That's why you must put the
class definition in a separate file and include this file in all pages
who use $_SESSION (even if they don't access the 'foo' element).