Page 1 of 1

Question on GLOBALS (yes, I read the sticky)

Posted: Fri Feb 07, 2003 11:58 am
by firemyst
Hi there,

I read the sticky, and am aware of the GLOBALS being turned off now by default. However, does this affect FORM variables that we don't reference using the GLOBALS array?

For example:

FORM
INPUT TYPE="text" NAME="email"
blah blah blah
/FORM

In my future PHP scripts, will the following still work with the register globals turned off? :

function PrintAddr() {
global $email;
echo ("Your email address was: " . $email);
}

Thanks!

Re: Question on GLOBALS (yes, I read the sticky)

Posted: Fri Feb 07, 2003 12:09 pm
by hedge
firemyst wrote:Hi there,

I read the sticky, and am aware of the GLOBALS being turned off now by default. However, does this affect FORM variables that we don't reference using the GLOBALS array?

For example:

FORM
INPUT TYPE="text" NAME="email"
blah blah blah
/FORM

In my future PHP scripts, will the following still work with the register globals turned off? :

function PrintAddr() {
global $email;
echo ("Your email address was: " . $email);
}

Thanks!
No you're script will not work.

with globals on a global variable $email will be created, with it off the global variable $email will not be defined. It will be available as $_POST['email']

Posted: Fri Feb 07, 2003 12:24 pm
by hob_goblin
infact, $_POST is a superglobal so if you changed your function to:

Code: Select all

function PrintAddr() { 
echo ("Your email address was: " . $_POSTї'email']); 
}
you wouldn't even have to set the variable as global.

Posted: Sat Feb 08, 2003 4:43 am
by volka
:?: it's the first example in the sticky thread ;)