php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3897 Can't register to a session from within an object
Submitted: 2000-03-22 12:00 UTC Modified: 2002-09-30 20:05 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ronen at greyzone dot com Assigned:
Status: Not a bug Package: Misbehaving function
PHP Version: 3.0.15 OS: RedHat Linux6.1
Private report: No CVE-ID: None
 [2000-03-22 12:00 UTC] ronen at greyzone dot com
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?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-30 20:05 UTC] hholzgra@php.net
... 'cause you can only register variables 
from the global namespace and not from
variables local to functions or methods
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 07:01:26 2019 UTC