RE: [PHP] What does register_globals do?

2002-07-22 Thread Matt Schroebel

 From: Matt Babineau [mailto:[EMAIL PROTECTED]] 
 Sent: Monday, July 22, 2002 3:59 PM
 Subject: [PHP] What does register_globals do?
 
 I have never had a clear understanding about what this does, 
 the php.ini
 has an explanation but being newer to PHP I don't understand it very
 well. Could someone prodive a human explanation about what
 register_globals does and why it is so important?

Register globals makes it *really* easy to code in php.  It's what takes the uri or 
posted form data, and turns them into global variables in your script.  

So if a url looked like:
http://www.fakename.com/index.php?target=help

and with register-globals on, php will create a variable, $target, which has the value 
'help' in it.  It's very useful and friendly but, if you don't initialize your 
variables then some non-so-nice person could initialize them for you by passing them 
on the uri/post/cookie/etc so that your code no longer works as expected.
 
You're safe with it on if you always initialize variables, and set error_reporting to 
E_ALL while testing so you catch any you might otherwise miss.

If you leave it off, you need to use the associative arrays $_POST, $_GET etc.  The 
above example would be $_GET['target'].

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] What does register_globals do?

2002-07-22 Thread Martin Clifford

My way of thinking about is:

With register_globals ON, all variables defined are available anywhere in the script 
(with the exception of functions and classes, unless defined otherwise), whereas with 
register_globals OFF, they are only available through the superglobals for the 
respective variable types.

I'm sure there's a much better way to explain it, but it works for me :o)


Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/


 Matt Babineau [EMAIL PROTECTED] 07/22/02 03:59PM 
I have never had a clear understanding about what this does, the php.ini
has an explanation but being newer to PHP I don't understand it very
well. Could someone prodive a human explanation about what
register_globals does and why it is so important?
 
Matt Babineau
MCWD / CCFD
-
e:  mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] 
p: 603.943.4237
w:  http://www.criticalcode.com/ http://www.criticalcode.com 
PO BOX 601
Manchester, NH 03105
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] What does register_globals do?

2002-07-22 Thread Matt Schroebel

 From: Martin Clifford [mailto:[EMAIL PROTECTED]] 
 Sent: Monday, July 22, 2002 4:21 PM
 Subject: Re: [PHP] What does register_globals do?
 My way of thinking about is:
 
 With register_globals ON, all variables defined are available 
 anywhere in the script (with the exception of functions and 
 classes, unless defined otherwise), whereas with 
 register_globals OFF, they are only available through the 
 superglobals for the respective variable types.

That's not quite right.  Php's variable scoping is different than most langauges.  
Variables inside a function are always local, even with register_globals on (this has 
something to do with Rasmus' life experiences at IBM). So you would need to use global 
on a variable inside a function (unless it's passed in) and except for the 'magic' 
global arrays, $_POST, $_GET, $_COOKIE, $_SERVER, etc

--- register_globals on --
http://localhost/index.php?target=help

?php

function echo_out() {
  global $target;
  echo $targetbr;
}

echo_out();
?

--- register_globals off --
http://localhost/index.php?target=help

?php

function echo_out() {
  echo {$_GET['target']}br;
}

echo_out();
?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] What does register_globals do?

2002-07-22 Thread Martin Clifford

unless defined otherwise was what I said.  When I said that, I simply meant that you 
declare the variables as global within the function and/or class.

Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/


 Matt Schroebel [EMAIL PROTECTED] 07/22/02 04:41PM 
 From: Martin Clifford [mailto:[EMAIL PROTECTED]] 
 Sent: Monday, July 22, 2002 4:21 PM
 Subject: Re: [PHP] What does register_globals do?
 My way of thinking about is:
 
 With register_globals ON, all variables defined are available 
 anywhere in the script (with the exception of functions and 
 classes, unless defined otherwise), whereas with 
 register_globals OFF, they are only available through the 
 superglobals for the respective variable types.

That's not quite right.  Php's variable scoping is different than most langauges.  
Variables inside a function are always local, even with register_globals on (this has 
something to do with Rasmus' life experiences at IBM). So you would need to use global 
on a variable inside a function (unless it's passed in) and except for the 'magic' 
global arrays, $_POST, $_GET, $_COOKIE, $_SERVER, etc

--- register_globals on --
http://localhost/index.php?target=help 

?php

function echo_out() {
  global $target;
  echo $targetbr;
}

echo_out();
?

--- register_globals off --
http://localhost/index.php?target=help 

?php

function echo_out() {
  echo {$_GET['target']}br;
}

echo_out();
?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php