|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-06 01:48 UTC] sniper@php.net
[2004-07-22 06:42 UTC] phpbr at ecartz dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 15:00:01 2025 UTC |
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.