Re: Re: isset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bret Hughes wrote:
> On Wed, 2005-02-16 at 07:54, Matthew Weier O'Phinney wrote:
>> * Bret Hughes <bhughes@xxxxxxxxxxxxx>:
>> > I just wish there was a use strict; sort of deal so I would not have
>> to
>> > hunt down logic errors due to mistyping a variable name.
>>
>> There is, in PHP5: E_STRICT. From the manual
>> (http://php.net/manual/en/ref.errorfunc.php#errorfunc.constants):
>>
>>     Run-time notices. Enable to have PHP suggest changes to your
>>     code which will ensure the best interoperability and forward
>>     compatibility of your code.
>>
>
> Hmm.  Good tip thanks.  chalk up another reason to upgrade to 5.
> getting close to haveing enough reasons to do so :)
>
> E_STRICT is closer but still does not warn of assigning to undeclared
> variables in or out of a class. bummer.

Assigning to an undeclared variable out of a class has no meaning in PHP,
because there are no declarations of variables outside of a class.

Declarations of variables inside of a class are pretty much for
documentation or initialization to a constant, but to be consistent with
the general theme of PHP assignment and PHP as a loosely-typed language,
it's perfectly legal syntactically and logically to assign to a new
property on a class.

So you're probably never gonna see a warning for assigning to an
undeclared variable, even in the class system...  It would have to be,
like, E_SO_STRICT_YOU_SHOULD_BE_USING_C_ANYWAY :-)

You SHOULD be using E_NOTICE to get warned when you *USE* an unassigned
variable/propery/element and PHP is forced to initialize it.

That will catch a bunch of your variable name typos -- And also will often
let you know you typed it wrong in the place where you did the assignment.
EG:

<?php
  $mispeled = 'test'; //line 2
  echo $mispelled; //line 3
?>

The typo is in the assignment, but you'll get warned in line 3.  Composing
a more convoluted example involving a class and 100 lines of code is left
as an exercise for the reader.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux