Re: Newbie question about variable scope in Apache 2.0 & PHP
| From: | Justin French | Date: | Thu, 08 May 2003 00:48:13 +0000 |
| Subject: | Re: Newbie question about variable scope in Apache 2.0 & PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146771@lists.php.net to get a copy of this message | ||
on 08/05/03 4:17 AM, Steve Henderson (steve@futurephase.com) wrote:
> One other question: Is there a reason to prefer one method over another
> from an efficiency standpoint?
The odl way (register globals on) took the get (+ post, session & other)
variables and made them into short variables like $id.
The problem was that you'd have no way of knowing if the variable came from
get, post, session, etc etc, since they all overwrote each other in an order
specified in php.ini.
So, in theory, you could be "relying" on a variable like $validLoggedInUser
to exist as a session variable, but I might overwrite or bypass that via a
GET variable or something else, and you'd have no way of knowing, unless you
initialised your variables in the script.
So, now you *know* that $_SESSION['isValidUser'] is definitely a session
variable, and $_GET['id'] is definitely a variable from the URL.
At first, I did something like...
<?
$id = $_GET['id'];
?>
... at the top of my script, but now I just work with $_GET['id'] directly.
Justin French