#20728 [Csd->Opn]: $_SESSION can be broken with "global"

From: Date: Mon, 02 Dec 2002 01:06:01 +0000
Subject: #20728 [Csd->Opn]: $_SESSION can be broken with "global"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-26337@lists.php.net to get a copy of this message
ID: 20728 User updated by: mikemc-phpbug@contactdesigns.com Reported By: mikemc-phpbug@contactdesigns.com -Status: Closed +Status: Open Bug Type: Session related Operating System: Linux 2.4.x PHP Version: 4.2.3 New Comment: Hello, This code is incorrect - I must have pasted over the code after I modified it during testing as $foobar is not a reference, but a copy. Here is what it should be (please note that you will have to hit reload after the first hit as session gets created on the first hit - so load it and hit reload - and then view the output): <?php session_start(); echo 'Before session modifications:<br><pre>'; var_dump($_SESSION); $_SESSION['foobar'] = 1; $foobar =& $_SESSION['foobar']; global $foobar; $foobar = 3; echo '</pre>After session modifications:<br><pre>'; var_dump($_SESSION); ?> Previous Comments: ------------------------------------------------------------------------ [2002-12-01 16:13:01] sniper@php.net I get this normal output: Before session modifications: array(1) { ["foobar"]=> int(1) } After session modifications: array(1) { ["foobar"]=> int(1) } No bug here. (using PHP 4.3.0-dev) ------------------------------------------------------------------------ [2002-12-01 16:07:16] mikemc-phpbug@contactdesigns.com Hello, I don;t think it is quote as easy as saying "Don't use global with the autoglobal arrays.". Please read my original bug post. I went out of my way to be very detailed so that I don't waste your time - this does nobody any good though if you don't take the time to read it. More specifically, this is the part I am referring to: <ORIGNAL BUG POST> So now you are asking that is interesting, but why would you ever want to "global" an autoglobal. Good question! There would be no purpose in doing this since $_SESSION is always in scope. Well, this bug presented itself to me in an application where there was a reference to a portion of $_SESSION. Since the application is over 5000 lines of code, we will view a highly condensed test version of this: <?php session_start(); echo 'Before session modifications:<br><pre>'; var_dump($_SESSION); $_SESSION['foobar'] = 1; $foobar = $_SESSION['foobar']; global $foobar; $foobar = 3; echo '</pre>After session modifications:<br><pre>'; var_dump($_SESSION); ?> </ORIGNAL BUG POST> So the bug presents itself when you "global" a reference to an array element of an autoglobal as well. Perhaps, I should have used this as the original code example. Please take the time to read the full bug post. Thank You, Mike ------------------------------------------------------------------------ [2002-11-29 20:58:08] sniper@php.net Don't use global with the autoglobal arrays. ------------------------------------------------------------------------ [2002-11-29 17:59:17] mikemc-phpbug@contactdesigns.com Hello, I have compiled the latest snap shot at http://snaps.php.net/php4-latest.tar.gz. The only change I had to make for the PHP compiling process was to update my version of curl since the snapshot requires curl-7.10.2 (the latest stable release). It compiled fine, I restarted the web server, and the same problem still occurs with the same code from my original bug post. Please let me know if you need any additional information. Mike ------------------------------------------------------------------------ [2002-11-29 15:23:07] sniper@php.net Please try using this CVS snapshot: http://snaps.php.net/php4-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-latest.zip ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/20728 -- Edit this bug report at http://bugs.php.net/?id=20728&edit=1

« previous php.bugs (#26337) next »