Re: "php -l" - does it find *anything*?

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

 



On Tue, 2010-07-06 at 10:54 +0200, Gary . wrote:

> Or, alternatively put, is there any way to find the kind of problems in
> foo2 & foo3 (below), at "*compile* time"?
> 
> ,----[ lint-test.php ]
> | <?php
> |
> | error_reporting(E_ALL | E_STRICT);
> |
> | function foo1()
> | {
> |     $bar = 'cheese';
> |     echo $bar;
> | }
> |
> | function foo2()
> | {
> |     $bar = 'cheese';
> |     echo 'cheese';
> | }
> |
> | function foo3()
> | {
> | //    $bar = 'cheese';
> |     echo $bar;
> | }
> |
> | foo1();
> | foo2();
> | foo3();
> |
> | ?>
> `----
> 
> I only get errors displayed when code happens to pass down the code
> path, i.e. at runtime:
> ,----
> | /home/jg/work $ php -l lint-test.php
> | No syntax errors detected in lint-test.php
> | /home/jg/work $ php lint-test.php
> | cheesecheese
> | Notice: Undefined variable: bar in
> | /home/jg/work/lint-test.php on line 20
> |
> | Call Stack:
> |     1.0000      61488   1. {main}()
> |     /home/jg/work/lint-test.php:0
> |     1.0000      61680   2. foo3()
> |     /home/jg/work/lint-test.php:25
> `----
> 
> If foo3 never happens to be called when I am doing my testing (for
> example if the call is in some "if" branch that is never exercised) then
> it only gets found in production, so I would like to find this kind of
> thing using a static analyser. The kind of problem in foo2 I could live
> with, but would like to find as well, if possible. (Obviously I am using
> these two example problems as indicative of the type of things I want to
> find, it isn't an exhaustive list!)
> 
> BTW, what problems *does* "php -l" pick up? I can't find a description
> anywhere.
> 


According to the man page for php, the -l flag only checks the syntax,
so a warning wouldn't be displayed, as technically it's not a
show-stopper. Maybe some sort of unit testing would help pick out these
sorts of issues? As PHP isn't a compiled language, I guess it's harder
for it to pick up on things like this. You don't need to declare a
variable before using it in PHP like you do in a compiled language
(without getting into the murky territory of compiled PHP!) so some
things might only be picked up by unit testing.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[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