I am a beginner in PHP programming. I was trying to store object variables as session variables, so that we don't have to create an object every time the page loads.
I have a simple class file simple.php
<?php
class simple{
function dummy(){
print "TEST SUCCESSFUL!\n";
}
}
?>
Then I created a simple .php which starts a new session and registers the object-variable of the class.
// test1.php
<?php
require ("simple.php");
session_start();
$CLSOBJ=new simple();
session_register("CLASSOBJ");
$CLASSOBJ=$CLSOBJ;
print isSet($_SESSION['CLASSOBJ']);
$CLASSOBJ->dummy();
?>
This file works fine and it prints the required result.
In the other .php files I have added the following lines:
Eg:// test2.php
<?php
require("simple.php");
session_start();
print isSet($_SESSION['CLASSOBJ']);
$CLASSOBJ->dummy();
?>
Here in test2.php the session variable is active. So, it outputs "1" for
'print isSet($_SESSION['CLASSOBJ']);'
but a fatal error like 'Call to a member function on a non-object in' is coming for '$CLASSOBJ->dummy();' . Any idea?Pls help....