note 11288 deleted from language.oop by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 19:04:28 +0000 |
| Subject: | note 11288 deleted from language.oop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162576@lists.php.net to get a copy of this message | ||
Note Submitter: buzz77 at gmx dot net
----
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:
<?php
// 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.
<?php
// 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:
require("simple.lib.php");
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)