Jump to content

$GLOBALS bug


silkfire

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/236836-globals-bug/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/236836-globals-bug/#findComment-1217410
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.