PHP 4.0 Bug #7558 Updated: session - objects in arrays

From: Date: Thu, 02 Nov 2000 04:28:07 +0000
Subject: PHP 4.0 Bug #7558 Updated: session - objects in arrays
Groups: php.dev 
Request: Send a blank email to php-dev+get-36738@lists.php.net to get a copy of this message
ID: 7558 User Update by: info@borderblue.com Status: Open Bug Type: *Session related Description: session - objects in arrays I'm using php.ini-optimized with register_globals = Off, so I access session variables using $HTTP_SESSION_VARS["blah"]. This is defined as an array of objects. I'm able to access properties such as $HTTP_SESSION_VARS["blah"][0]->property, but I can't run methods by doing $HTTP_SESSION_VARS["blah"][0]->method(). The following test script illustrates the problem, reloading the page should increase the array size of "blah" each time. I found that I could work around the problem by copying the session variable to a local variable, doing the methods on that, and then copying back. I compiled PHP as a dynamic DSO module using: ./configure --with-mysql --with-apxs=/usr/local/apache/bin/apxs Here is the test script: /* reload the page to increase the array size of "blah" */ class Test { var $item; function run() { $this->item = 1234; } } session_start(); session_register("blah"); if (!isset($HTTP_SESSION_VARS["blah"])) { $HTTP_SESSION_VARS["blah"] = array(); } echo "array size before = ",sizeof($HTTP_SESSION_VARS["blah"]),"<br>n"; $S = sizeof($HTTP_SESSION_VARS["blah"]); $HTTP_SESSION_VARS["blah"][$S] = new Test; /** this doesn't work *******************/ // $HTTP_SESSION_VARS["blah"][$S]->run(); /****************************************/ /** this works **************************/ $SESSION = $HTTP_SESSION_VARS; $SESSION["blah"][$S]->run(); $HTTP_SESSION_VARS = $SESSION; /****************************************/ echo "array size after = ",sizeof($HTTP_SESSION_VARS["blah"]),"<br>n"; Previous Comments: --------------------------------------------------------------------------- [2000-10-31 19:51:37] info@borderblue.com I'm using php.ini-optimized with register_globals = Off, so I access session variables using $HTTP_SESSION_VARS["blah"]. This is defined as an array of objects. I'm able to access properties such as $HTTP_SESSION_VARS["blah"][0]->property, but I can't run methods by doing $HTTP_SESSION_VARS["blah"][0]->method(). The following test script illustrates the problem, reloading the page should increase the array size of "blah" each time. I found that I could work around the problem by copying the session variable to a local variable, doing the methods on that, and then copying back. I compiled PHP as a dynamic DSO module using: ./configure --with-mysql --with-apxs=/usr/local/apache/bin/apxs Here is the test script: /* reload the page to increase the array size of "blah" */ class Test { var $item; function run() { $this->item = 1234; } } session_start(); session_register("blah"); if (!isset($HTTP_SESSION_VARS["blah"])) { $HTTP_SESSION_VARS["blah"] = array(); } echo "array size before = ",sizeof($HTTP_SESSION_VARS["blah"]),"<br>n"; $S = sizeof($HTTP_SESSION_VARS["blah"]); $HTTP_SESSION_VARS["blah"][$S] = new Test; /** this doesn't work *******************/ // $HTTP_SESSION_VARS["blah"][$S]->run(); /****************************************/ /** this works **************************/ $SESSION = $HTTP_SESSION_VARS; $SESSION["blah"][$S]->run(); $HTTP_SESISON_VARS = $SESSION; /****************************************/ echo "array size after = ",sizeof($HTTP_SESSION_VARS["blah"]),"<br>n"; --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7558

« previous php.dev (#36738) next »