note 11288 added to Classes and Objects
| From: | buzz77 at gmx dot net | Date: | Wed, 14 Feb 2001 13:33:19 +0000 |
| Subject: | note 11288 added to Classes and Objects | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11043@lists.php.net to get a copy of this message | ||
You can also store object variables as session variables, so that you don't have to create an
object every time the page loads.
Let's see how:
here is my simple class file:
// simple.lib.php
class simple
{
function dummy
{
print "TEST SUCCESSFUL!\n";
}
}
Then, I create a simple .php which starts a new session and registers the object-variable of the
"simple"-class.
// test1.php
require ("simple.lib.php");
session_start();
session_register("CLASSOBJ");
$CLASSOBJ=new simple();
That's all.
In the following .php-files you've only to add the following lines:
session_start();
To test out if it works, simply call:
$CLASSOBJ->dummy();
and it will print the message.
I tried it out also with quite huge classes, and it always worked (I think the pointer to the
instanciated class is stored and the class object itself won't be deleted if you eg. change to
another .php-page)
http://www.php.net/manual/en/language.oop.php