How to recursively check syntax of PHP files

The executable of PHP supports the ‘-l’ option, that checks the syntax instead of parsing the file.
Using the command ‘find’, it’s possibile to do a interesting operation: syntax checking of all the files recursively, to avoid parse errors in some script !!

find ./ -type f -name *.php -exec php -l {} ;

the result will be a list of files, example:

No syntax errors detected in ./codebase/controller/
No syntax errors detected in ./codebase/controller/
Errors parsing ./codebase/controller/site/
No syntax errors detected in ./codebase/controller/

We can improve the script and print only the file with suntax errors using ‘grep’

find ./ -type f -name *.php -exec php -l {} ; | grep “Errors parsing “;

To launch it from a PHP script

passthru(‘find ./ -type f -name *.php -exec php -l {} ; | grep “Errors parsing ” ‘);

Updated: To skip .svn directories add the option :
-not -regex ‘.*/.svn/*.*’