Question

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.

Was it helpful?

Solution

I believe this is one of the features of PHPLint.

OTHER TIPS

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

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

php -l FILE

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top