ID: 3897
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Bogus
Bug Type: Misbehaving function
Operating System: RedHat Linux6.1
PHP Version: 3.0.15
New Comment:
... 'cause you can only register variables
from the global namespace and not from
variables local to functions or methods
Previous Comments:
------------------------------------------------------------------------
[2000-03-22 12:00:26] [EMAIL PROTECTED]
When I try to register a variable to a session from within a class all
I get is a variable name with no value associated with it.
I have an initial file which looks like this:
<?
class DOG{}
class USER{
function USER(){
session_start();
$tmp=new DOG();
$tmp->test="howdy";
session_register('tmp');
}
}
$dog=new User();
echo "How's about it.";
?>
Then on a different page I have:
<?
session_start();
echo $tmp->test. "<BR>";
echo session_id();
?>
the only thing echoed out is the PHPSESSID value.
when I go and take a look at the session file I see no value:
>more sess_afb860c13c89fd697ad261ab8372e184
>!tmp|
This problem doesn't happen when I attempt to register from outside a
class. Here's an example of what DOES work:
file noclass.html:
<?
class DOG{
var $name;
}
$mydog=new DOG();
$mydog->name="poochy";
session_start();
session_register("mydog");
echo "session id: ".session_id()."<br>n";
echo "My dog's name is".$mydog->name."<br>n";
echo "is mydog registered? ".session_is_registered("mydog");
?>
and the the next file noclass2.html:
<?
class DOG{
var $name;
}
session_start();
echo "session id: ".session_id()."<br>n";
echo "mydog's name is: ".$mydog->name."<br>n";
?>
The output is as follows:
noclass.html:
session id: 7713588e3fbce54b0760c8a082fd5cc3
My dog's name ispoochy
is mydog registered? 1
---------------------------------------
noclass2.html:
session id: 7713588e3fbce54b0760c8a082fd5cc3
mydog's name is: poochy
So, obviously an object CAN be stored to a session, but what is stored
is only the data associated with the object properties.
I return to my original question- why is it that an object can't be
registerd to a session from within a class?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=3897&edit=1