Bug #3897: Can't register to a session from within an object

From: Date: Wed, 22 Mar 2000 17:00:26 +0000
Subject: Bug #3897: Can't register to a session from within an object
Groups: php.dev 
Request: Send a blank email to php-dev+get-17141@lists.php.net to get a copy of this message
From: ronen@greyzone.com Operating system: RedHat Linux6.1 PHP version: 3.0.15 PHP Bug Type: Misbehaving function Bug description: Can't register to a session from within an object 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?

« previous php.dev (#17141) next »