Date: 11/01/00
- Next message: John Donagher: "Re: [PHP-DEV] email"
- Previous message: info <email protected>: "[PHP-DEV] PHP 4.0 Bug #7558 Updated: session - objects in arrays"
- Next in thread: waldschrott <email protected>: "[PHP-DEV] PHP 4.0 Bug #7558 Updated: session - objects in arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 7558
User Update by: info <email protected>
Status: Open
Bug Type: *Session related
Description: session - objects in arrays
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.
Previous Comments:
---------------------------------------------------------------------------
[2000-11-01 23:28:07] info <email protected>
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 <email protected>
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
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: John Donagher: "Re: [PHP-DEV] email"
- Previous message: info <email protected>: "[PHP-DEV] PHP 4.0 Bug #7558 Updated: session - objects in arrays"
- Next in thread: waldschrott <email protected>: "[PHP-DEV] PHP 4.0 Bug #7558 Updated: session - objects in arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

