Re: Suggestion: global variables being accessed in localscope
| From: | Richard Lynch | Date: | Sun, 11 Feb 2007 06:15:56 +0000 |
| Subject: | Re: Suggestion: global variables being accessed in localscope | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-27995@lists.php.net to get a copy of this message | ||
On Thu, February 8, 2007 7:43 pm, Christian Schneider wrote:
> Guilherme Blanco wrote:
>> Brian,I am sorry about the message indentation... Seems
>> PHP-Internals
>> list does not like M$ Live(r) Mail!
>
> Please use plain text mail as your messages are a PITA to read,
> thanks.
Or very easy to read, as the spam filter just junks it...
:-v
>> you can see, the only change needed is in a throw-able error
>> (Undefined
>> variable), which does a second look-up in the symbolTable.Doing
>> this, you do not need to use $GLOBALS nevermore! And also, global
>> can
>
> You didn't grasp two of the major PHP features (not bugs!):
> 1. Every variable you access inside a function is local unless
> explicitely imported (through $GLOBALS, global or superglobals) from
> the
> global scope.
And that's the way it should be, unless you really like tracking down
obscure bugs from totally unrelated code messing with your variables.
> 2. Accessing undefined variables is normal and not an error (not
> everybody agrees here but lots of people consider this a big plus).
Actually, it's not at all normal, and PHP throws an E_NOTICE.
It's your own fault if you haven't turned that on in your
error_reporting.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?