ID: 28352 Updated by: [EMAIL PROTECTED] Reported By: hpdl at oscommerce dot com -Status: Open +Status: Bogus Bug Type: Session related Operating System: Linux PHP Version: 4.3.4 New Comment:
This has been explained in several bug reports. Please read the 'Session related' ones with text 'references' in them.. Previous Comments: ------------------------------------------------------------------------ [2004-05-10 19:02:18] hpdl at oscommerce dot com Description: ------------ A global variable which references a session variable inside a class loses its global scope. Reproduce code: --------------- <?php session_start(); class test { function test() { global $b; if (!isset($_SESSION['a'])) { $_SESSION['a'] = 0; } $b =& $_SESSION['a']; } } $test = new test; $b++; echo $b; echo '<br><br>'; echo '<a href="' . basename($_SERVER['PHP_SELF']) . ((defined('SID') && strlen(SID) > 0) ? '?' . SID : '') . '">reload</a>'; ?> Expected result: ---------------- The counter shown should be incremented on each page reload. Actual result: -------------- The counter does not get incremented and stays at 1. Changing the following line: $b =& $_SESSION['a']; to: $GLOBALS['b'] =& $_SESSION['a']; produces the expected result. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28352&edit=1