|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-10-31 19:51 UTC] info at borderblue dot 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";
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
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";