Re: Variable declaration
| From: | Rasmus Lerdorf | Date: | Thu, 27 Sep 2001 08:23:14 +0000 |
| Subject: | Re: Variable declaration | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68967@lists.php.net to get a copy of this message | ||
That is the nature of a loosely typed scripting language. If you prefer a
strongly typed compiled language, there are plenty of those available.
-Rasmus
On Thu, 27 Sep 2001, * R&zE: wrote:
> > Like I said, that line does both. It sets the type internally to an
> > integer and assigns the value.
> >
> > -Rasmus
>
> What he (Alberto) is looking for, and what I would prefer to, is to
> really explicitly declare a variable. There's a difference between a
> compiler that requires you to declare (integer $Test;) a variable
> _before_ you start using it ($Test = 3;). Ofcourse I know that PHP
> internally declares it, but it's not the same thing.
>
> When the compiler forces you to declare all variables you're gonna
> use it gives a better view of which variables are used in the
> script, and besides that it doesn't allow you to make any mistakes
> of using undefined variables like it does now.
>
> The PHP compiler doesn't really check your code intensively. You can
> use any variable without the compiler complaining. Only at the
> moment that it reaches the variable and finds out it isn't defined,
> it tells you. It would be better to explicitly have to declare the
> variable. When the compiler starts it then shouldn't execute the
> code when it contains any variable that is not explicitly declared.
>
> But like I said, FAFAIK explicitly declaring variables isn't
> supported by PHP :(
>
>