RE: [PHP4BETA] Local variables
| From: | Samuel Liddicott | Date: | Tue, 16 Nov 1999 17:15:22 +0000 |
| Subject: | RE: [PHP4BETA] Local variables | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6299@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Faisal Nasim [mailto:swiftkid@bigfoot.com]
> Sent: Monday, November 15, 1999 02:56 PM
> To: php4beta@lists.php.net
> Subject: [PHP4BETA] Local variables
>
>
> Greetings,
>
> I would like to know if PHP4 supports local variables yet or not?
It has for years.
Every variable in a local scope (in a function) is local.
You have to use:
Global($var)
to get at a global variable.
> unset() is not a proper solution when using many variables
> under different scopes.
solution to what? I think you don't need it in your case/
> I couldn't find local() or some equivalent function in the PHP docs.
>
> An example to evaluate what I mean:
>
> $str = "whizkid";
> {
> $str = "faisal";
> print $str;
> }
> print $str;
>
>
> Would print "faisal" twice. But I declare it under the first scope, it
> should remain private or perhaps some keyword to make it private
> to the specific code block which I declare it in!
You don't get scopes like that, like you do in C (may be nice though).
You get a new scopt in a function definition.
> The above code should print:
> whizkidfaisal
> once $str inside the code block is declared to be local for that
> particular scope.
Hope this makes things clear.
Sam