#47173 [NEW]: $_SESSION reference inside function broken
| From: | tommyhp2 at yahoo dot com | Date: | Tue, 20 Jan 2009 19:27:32 +0000 |
| Subject: | #47173 [NEW]: $_SESSION reference inside function broken | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-133079@lists.php.net to get a copy of this message | ||
From: tommyhp2 at yahoo dot com
Operating system: Win03 R2 SP2 PHP ISAPI
PHP version: 5.2.8
PHP Bug Type: Session related
Bug description: $_SESSION reference inside function broken
Description:
------------
use of variable variables broken when reference inside a function in
conjunction with $_SESSION.
Thanks,
Tommy
Reproduce code:
---------------
Scenario 1:
<code>
session_start();
$arr =
array('idx1'=>'val1','idx2'=>'val2','idx3'=>'val3');
if (isset($_SESSION['arr']))
{
$arr =& $_SESSION['arr'];
} else {
$_SESSION =& $arr;
}
</code>
Works as intended (please see "Expected result").
Scenario 2:
<code>
function register_session($var)
{
global $$var;
if (isset($_SESSION[$var]))
{
$$var =& $_SESSION[$var];
} else
{
$_SESSION[$var] =& $$var;
}
}
session_start();
$arr =
array('idx1'=>'val1','idx2'=>'val2','idx3'=>'val3');
register_session('arr');
</code>
Does not work as intended (Please see "Actual result"). The variable $arr
is not referenced.
Expected result:
----------------
["_SESSION"]=>
&array(3) {
["idx1"]=>
string(4) "val1"
["idx2"]=>
string(4) "val2"
["idx3"]=>
string(4) "val3"
}
["arr"]=>
&array(3) {
["idx1"]=>
string(4) "val1"
["idx2"]=>
string(4) "val2"
["idx3"]=>
string(4) "val3"
}
Actual result:
--------------
["_SESSION"]=>
&array(1) {
["arr"]=>
array(3) {
["idx1"]=>
string(4) "val1"
["idx2"]=>
string(4) "val2"
["idx3"]=>
string(4) "val3"
}
}
["arr"]=>
array(3) {
["idx1"]=>
string(4) "val1"
["idx2"]=>
string(4) "val2"
["idx3"]=>
string(4) "val3"
}
--
Edit bug report at http://bugs.php.net/?id=47173&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47173&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47173&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47173&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47173&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47173&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47173&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47173&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47173&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47173&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47173&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47173&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47173&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47173&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47173&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47173&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47173&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47173&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47173&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47173&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47173&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47173&r=mysqlcfg