You are here: Re: [PHP] More toroughly checking a script before execution « PHP « IT news, forums, messages
Re: [PHP] More toroughly checking a script before execution

Posted by Rasmus Lerdorf on 07/22/05 02:03

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация