> -----Original Message-----
> From: Matthew Aznoe [mailto:[EMAIL PROTECTED]]
> Subject: [PHP] Variable name declarations?
> However, I do have one complaint about PHP that seems to have a tendency to
> bite me far too often, and that is the lack of variable declaration.  While
> I do not think the type of the variable should be required, requiring the
> user to specify which variable names are going to be used I think would be
> useful.  The reason why I believe this is important is in debugging.  I have
> been caught many times misspelling a variable name slightly (ie -> ei), and
> since PHP does no variable name checking, sometimes it takes a while to
> discover the error.  If each variable name had to be declared prior to use,
> it would eliminate this problem by warning the user each time an undeclared
> name was used.

you are basically describing the "use strict;" pragma of perl.

if you declare "use strict;" at the beginning of a perl script,
you must then declare all variables before using them (among
other things that "use strict" prohibits, but variable declaration
is by far the most noticeable effect of "use strict")

my $num = 5;            #good

$num = 5;               #error

but the great thing is, is that you can turn "strict" mode off
for specific code blocks if you find a need to get a little
loose with the rules.

no strict;
$x = 5;         #no error

i wish PHP had an equivilent to perl's "use strict"... 
it would certainly save us all a lot of time, and probably
make us clean our code up a little bit :)

> I do not believe that this would sacrifice very much freedom in the
> language, and it would certainly make debugging and maintainence easier on
> the developer. 

if PHP make variable declaration an optional thing by use of
something similar to perl's "use strict" pragma, then it wouldnt
sacrifise anything... becuase only people who wanted it would
use it.

if PHP were to mandate variable declaration for all scripts all
the time, then it would certainly sacrifise a lot... 

> Does anyone else have any thoughts on this?> 

yes.  i love the idea... just as long as it's an optional feature
that can be turned on and off as the programmer needs.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to