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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.