Re: More toroughly checking a script before execution

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

 



Markus Fischer wrote:
> Hi,
> 
> is there a way to have a more torough checking of PHP code before
> executing?
> 
> I can't remember the number of times when I try to read a variable which
> hasn't assigned a value yet. This increases as projects are getting
> bigger and more files are used.
> 
> I know that due it's loosely typed nature, it wouldn't be possible to
> detect things like this:
> 
> $foo = "bar";
> $$foo = "baz";
> echo $bar;
> 
> but that would be okay with me. At least it should catch things like
> _before_ starting execution:
> 
> - read variables not assigned a value before
> - verify that a function/method is actually defined
> 
> I'm willing to accept a longer time PHP starting up because of this. I'm
> seeing it's main usefulness when using with the cli application to have
> it ran on code before it goes live or something.
> 
> This would speed up testing dramatically, as it wouldn't be necessary to
> go through all test paths just to realize that a function/method call
> was misspelled or so. Basically it's like the compiling stage done in
> e.g. Java (oh no, did I wrote the J.. word? ;).
> 
> I'm also aware that certain modern IDEs provide lookup
> features/introspecton at least for function/methods, but unfortunatley
> it's not everyones favourite.
> 
> thanks for any pointers,
> 
> - Markus
> 

Sounds like you just need to turn on E_NOTICE.  At least for your
variable access stuff assuming your test case actually hits that part of
the code.

If you are talking about complete code coverage letting you catch any
such mistyped variables or functions, that is simply impossible to do at
that level because variables and function names can be defined at
runtime.  Just because a function doesn't exist at compile time doesn't
mean that it won't be created before the call to it at runtime.  And it
doesn't need to be as complicated as you make it out to be with your
variable variable example.  A simple conditional include completely
changes the nature of everything at runtime.

What you really need is to create decent regression tests and use a code
coverage tool to make sure your tests cover your code well.  Xdebug can
do the code coverage check for you.

-Rasmus

-- 
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