silkfire Posted May 19, 2011 Share Posted May 19, 2011 Has anyone encountered this bug which had me banging my head against the desk all morning? In the beginning I registered a $GLOBALS['direction'] that equalled to a radio button value. Later in the script I declare a variable $direction that for some strange reason took the value of $GLOBALS['direction'] without me even writing so. So when i compared them they had the same value. As soon as I changed $direction to $directionx the script worked and the value wasn't "copied" to the $GLOBALS. What's up? Quote Link to comment https://forums.phpfreaks.com/topic/236836-globals-bug/ Share on other sites More sharing options...
JonnoTheDev Posted May 19, 2011 Share Posted May 19, 2011 This is not a bug. This is supposed to happen. By using $GLOBALS you reference any variables you create a key for in the global scope! You should use caution with global variables as you are experiencing the issues now. I avoid like the plague or use very scarcely such as a database connection handle that is required in a function i.e function foobar() { global $db; } Read the PHP manual http://php.net/manual/en/reserved.variables.globals.php Global variables are dangerous! Quote Link to comment https://forums.phpfreaks.com/topic/236836-globals-bug/#findComment-1217410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.