tags:

views:

383

answers:

5

Is there any tool that will help detect potential errors like "undefined function" in a PHP script before runtime?

For example, consider:

<?php
zarfnutz ( 'blah' );
?>

If you ask the PHP command line interface to check that for syntax errors, it responds that there are none. But of course the script will fail if you try to run it, because there's no function called "zarfnutz".

I understand that if the language is self-referential enough, it's literally not possible to create such a tool which is guaranteed accurate (I don't know if PHP is in fact self-referential enough). But in any case, there could definitely be a tool that could at least warn you that "zarfnutz" might be undefined, and such a tool would be very helpful to me.

Does anyone know of one?

Thanks in advance.

+3  A: 

I believe this is one of the features of PHPLint.

Jekke
Great, thanks, I'll check it out.
A: 

Sounds a little like the Halting Problem, if you do manage to solve it you'll also be able to solve the world's energy crisis by harnessing the power of Alan Turing spinning in his grave :)

Paul Dixon
I understand this. That's why I explicitly noted that I understand it, in my original statement, and explicitly clarified that even something which would merely *warn* -- which is *certainly* possible -- would be very helpful.
I know, my post was just for fun. The PHPLint link is good, not come across it, it got a +1 from me too.
Paul Dixon
A: 

Well, I don't know of a tool to do it, but function_exists and get_defined_functions are part of the PHP core.

R. Bemrose
A: 

Run php on the file with the lint flag (syntax check only):

php -l FILE
Nerdling
It doesn't pickup this type of problem.
Nick Presta
As I said, "If you ask the PHP command line interface to check that for syntax errors, it responds that there are none."
A: 

A way to check is to use function_exists(). It's not quite as flexible as checking via php -l, but it will get the job done.

gms8994
Thank you, but as I said, I'm trying to detect it *before* runtime.