|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-04-29 23:00 UTC] sniper@php.net
[2004-04-30 03:49 UTC] mmertinkat at justseven dot de
[2004-05-06 09:09 UTC] bart at mediawave dot nl
[2004-06-09 02:05 UTC] spy at spy dot zp dot ua
[2004-06-30 03:59 UTC] moriyoshi@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 23:00:01 2025 UTC |
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 ) ) )