|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-09-11 09:57 UTC] hdfou at yahoo dot fr
Description:
------------
A $GLOBALS value is updated and should not be updated.
Test script:
---------------
$GLOBALS['availableLanguages'] = array(
'fr' => array( 'n' => 'Français' ) ,
'en' => array( 'n' => 'English' )
);
$GLOBALS['lang']='fr';
echo 'At the biginning, $GLOBALS[\'lang\']=' . $GLOBALS['lang'] . '<br />' ;
foreach( $GLOBALS['availableLanguages'] as $lang => $value){
echo '$lang=' . $lang . '<br />';
}
// nowhere $GLOBALS['lang'] has been changed by the script but at the end
// $GLOBALS['lang'] = "en" instead of "fr".
echo '<br />$GLOBALS[\'lang\']="' . $GLOBALS['lang'] . '" ' . ($GLOBALS['lang']=='en' ? '<b style="color:red;">THIS SHOULD BE "fr"</b>' : '<b style="color:green;">OK</b>' ) ;
exit();
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 09:00:01 2025 UTC |
You're in the global scope with your "foreach". foreach( $GLOBALS['availableLanguages'] as $lang => $value){ That modifies the global $lang. I'd recommend to not use $GLOBALS.