From: mmertinkat at justseven dot de Operating system: Windows XP PHP version: 4.3.6 PHP Bug Type: Scripting Engine problem Bug description: Strange behaviour using references
Description: ------------ Just look at the code; it is reproducible with PHP 4.3.4, 4.3.5 and 4.3.6 on Windows and Linux. Reproduce code: --------------- <? $data = NULL; $data['settings']['account']['firstname'] = 'Johnny'; $data['settings']['account']['lastname'] = 'Walker'; $data['settings']['account']['username'] = 'johnny'; $data['settings']['account']['password'] = 'not secret'; /**********************************************/ print_r($data); $settings = $data['settings']; $account = &$settings['account']; // we're now going to change the account password and therefore // use the $account array as a "shortcut" (reference) to $settings['account'] $account['password'] = 'secret'; // write any changes into the data array $data['settings'] = $settings; /******************/ // the following two lines will (mistakenly?) touch the $data array ... $mysettings = $data['settings']; $mysettings['account']['password'] = 'very secret'; // ... whereas the next two lines don't change anything (as it should be) $myaccount = $data['settings']['account']; $myaccount['password'] = 'very very secret'; print_r($data); ?> Expected result: ---------------- Array ( [settings] => Array ( [account] => Array ( [firstname] => Johnny [lastname] => Walker [username] => johnny [password] => not secret ) ) ) Array ( [settings] => Array ( [account] => Array ( [firstname] => Johnny [lastname] => Walker [username] => johnny [password] => secret ) ) ) Actual result: -------------- Array ( [settings] => Array ( [account] => Array ( [firstname] => Johnny [lastname] => Walker [username] => johnny [password] => not secret ) ) ) Array ( [settings] => Array ( [account] => Array ( [firstname] => Johnny [lastname] => Walker [username] => johnny [password] => very secret ) ) ) -- Edit bug report at http://bugs.php.net/?id=28050&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28050&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28050&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28050&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28050&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28050&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28050&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28050&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28050&r=support Expected behavior: http://bugs.php.net/fix.php?id=28050&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28050&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28050&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28050&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28050&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28050&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28050&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28050&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28050&r=float