ID: 47173 Updated by: [email protected] Reported By: tommyhp2 at yahoo dot com -Status: Open +Status: Bogus Bug Type: Session related Operating System: Win03 R2 SP2 PHP ISAPI PHP Version: 5.2.8 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Do not do that.. Previous Comments: ------------------------------------------------------------------------ [2009-01-20 19:32:22] tommyhp2 at yahoo dot com Same problem w/ CVS PHP 5.2 - Windows x86 VC6 (thread safe)) [10.02MB] - 2009-Jan-20 12:00:00 ------------------------------------------------------------------------ [2009-01-20 19:27:31] tommyhp2 at yahoo dot com 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 this bug report at http://bugs.php.net/?id=47173&edit=1
