Question on GLOBALS (yes, I read the sticky)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
firemyst
Forum Newbie
Posts: 6
Joined: Sat Feb 01, 2003 5:33 pm

Question on GLOBALS (yes, I read the sticky)

Post 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!
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

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

Post 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']
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?: it's the first example in the sticky thread ;)
Post Reply