Firehed's Blog

Syntax check all of your php files

For my fellow CLI nerds out there, I recently found out that PHP has a syntax validation tool built in (php -l file.php). How handy! If you've ever left a comma off the middle of an array somewhere because you were reorganizing it or something to that effect, it can save you a lot of trouble. Unfortunately, it's only good for one file at a time.

I can't stand for that, so here's a shell script (written in PHP, naturally) that will check all of the files in your current folder, with a recursive option. Download it, extract it into /usr/bin, chmod +x it, and have fun.

http://www.firehed.net/files/lint.zip

usage: lint [-qR] [path]

options: 
    -q, --quiet:     disable verbose output
    -R, --recursive: recurse into subdirectories
    -h, --help:      display this help screen

Running lint alone will check all PHP files in the current directory. lint -R will recurse. lint -q does it quietly. lint -qR... well, you probably get the idea by now. You should also be able to pipe output into it, ex ls *_new.php | lint and just check those results. I don't really have enough bash-fu to test that functionality too thoroughly, but it should get the job done for you.

* Note: This was made a tested with PHP CLI 5.3.1 and I don't care to test it on earlier versions. That said, it will probably work with PHP >= 4.3.0. If you have great ideas for improvement, do let me know at firehed@gmail.com. It's one of my first reasonably useful shell scripts, so be gentle.