PHP 4.0 Bug #6161 Updated: Global variable acts strangely

From: Date: Tue, 15 Aug 2000 10:50:02 +0000
Subject: PHP 4.0 Bug #6161 Updated: Global variable acts strangely
Groups: php.dev 
Request: Send a blank email to php-dev+get-28889@lists.php.net to get a copy of this message
ID: 6161 User Update by: andrew@andrew.org Status: Open Bug Type: Session related Description: Global variable acts strangely Looks like I got away with fantasy. Anyway, I think I cornered the little bastard. look at "globtest2.phtml" : <? function increment_0() { global $a; session_start(); $a += 1; } function increment_1() { session_start(); global $a; $a += 1; } function increment_2() { session_start(); $a += 1; $GLOBALS["a"] += 1; } switch ($b) { case 0: increment_0(); break; case 1: increment_1(); break; case 2: increment_2(); break; } if ($a == 1) session_register("a"); echo $a, "<BR>\n"; echo "<A HREF='./globtest2.phtml?b=0'>increment_0()</A><BR>\n"; echo "<A HREF='./globtest2.phtml?b=1'>increment_1()</A><BR>\n"; echo "<A HREF='./globtest2.phtml?b=2'>increment_2()</A><BR>\n"; ?> if you do session_start() AFTER declaring a variable as global (as in increment_0() ), you lose the changes. I don't think this is how it's supposed to be. In the above examples, the first link isn't working properly. (BTW, remember to quit your browser to unload the session cookie) what about this? Luca (going to sleep now...) Full Bug description available at: http://bugs.php.net/?id=6161

« previous php.dev (#28889) next »