RE: [PHP] What does register_globals do?
| From: | Martin Clifford | Date: | Mon, 22 Jul 2002 20:42:55 +0000 |
| Subject: | RE: [PHP] What does register_globals do? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108936@lists.php.net to get a copy of this message | ||
"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 <MSchroebel@hsus.org> 07/22/02 04:41PM >>>
> 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();
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php