RE: [PHP] What does register_globals do?
| From: | Matt Schroebel | Date: | Mon, 22 Jul 2002 20:41:15 +0000 |
| Subject: | RE: [PHP] What does register_globals do? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108934@lists.php.net to get a copy of this message | ||
> From: Martin Clifford [mailto:MLC1@nrc.gov]
> 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 "$target<br>";
}
echo_out();
?>
------- register_globals off ----------
http://localhost/index.php?target=help
<?php
function echo_out() {
echo "{$_GET['target']}<br>";
}
echo_out();
?>