From: hpdl at oscommerce dot com
Operating system: Linux
PHP version: 4.3.4
PHP Bug Type: Session related
Bug description: Referencing Global Variables
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 bug report at http://bugs.php.net/?id=28352&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28352&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28352&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28352&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28352&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28352&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28352&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28352&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28352&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28352&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28352&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28352&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28352&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28352&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28352&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28352&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28352&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28352&r=float