|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-09-30 20:05 UTC] hholzgra@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 01:00:01 2025 UTC |
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?