PHP 4.0 Bug #7558 Updated: session - objects in arrays
| From: | waldschrott@php.net | Date: | Sat, 04 Nov 2000 00:41:22 +0000 |
| Subject: | PHP 4.0 Bug #7558 Updated: session - objects in arrays | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-37059@lists.php.net to get a copy of this message | ||
ID: 7558
Updated by: waldschrott
Reported By: info@borderblue.com
Status: Analyzed
Bug Type: *Session related
Assigned To:
Comments:
umh, in order to test this... well - PHP crashes on win32
and it does not work on Linux (did not check if segfaults)
Previous Comments:
---------------------------------------------------------------------------
[2000-11-01 23:41:25] info@borderblue.com
PLEASE NOTE:
------------
Ok, some comments on the above test code, it turns out I had a typo, so my "workaround"
doesn't work. Specifically, the line
$HTTP_SESSION_VARS = $SESSION;
was accidentally typed as
$HTTP_SESISON_VARS = $SESSION;
So the reason it worked is because the local $SESSION variable was being edited but it never got
copied back to the session. So restating the problems I'm seeing:
Objects inside arrays don't seem to work correctly in sessions. The devshed.com site has some
comments about this which say that maybe objects in arrays aren't properly deserialized in PHP
4.0.3 and 4.0.3pl1. The relevant url is at
http://www.devshed.com/Server_Side/PHP/Commerce3/comments.html
It does not help to copy the entire session variable to a local variable. However, I have some more
test results for the test code shown above, in particular:
/** this does not work ******************/
$SESSION = $HTTP_SESSION_VARS["blah"];
$SESSION[$S]->run();
$HTTP_SESSION_VARS["blah"] = $SESSION;
/****************************************/
/** this works **************************/
$SESSION = $HTTP_SESSION_VARS["blah"][$S];
$SESSION->run();
$HTTP_SESSION_VARS["blah"][$S] = $SESSION;
/****************************************/
So if you copy the object itself, which is inside an array, to a local variable and execute the
method there, you can copy back the result and the page seems to update properly when you reload.
---------------------------------------------------------------------------
[2000-11-01 23:28:07] 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_SESSION_VARS = $SESSION;
/****************************************/
echo "array size after =
",sizeof($HTTP_SESSION_VARS["blah"]),"<br>n";
---------------------------------------------------------------------------
[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