Re: Re: PHP 4.0 Bug #2193 Updated: Global declared variables not gobalu

From: Date: Mon, 30 Aug 1999 17:34:44 +0000
Subject: Re: Re: PHP 4.0 Bug #2193 Updated: Global declared variables not gobalu
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-10354@lists.php.net to get a copy of this message
At 18:26 30/08/99 , Michal Kara wrote:
a) Code which works standalone does not work when included from a function, which IMHO is not a good behavior.
I'll have to say that in this case, your opinion is simply wrong. Include() and require() execute the code in an included file as is and in the context of the include/require statement. Many factors can affect the way it behaves, including whether or not it is in a function scope. If you got any other impression - you got it wrong...
b) There is no simple way for the function to access the variable.
That's the idea of scope. You're not supposed to address any function local variables. You have to intentionally declare variables as global if you want them accessible from other scopes.
c) It should be noted win the "variable scope" chapter in the manual.
Well, provided the explanation of include and require are clear, it's not special in any way. Include()ing or require()ing a file is identical to copying and pasting the contents of that file where the include/require statement is, and scope rules apply all the same. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il

« previous php.dev (#10354) next »