Cheap PHP lint checking with Git

Running PHP's "built-in" lint checker (php -l) is a quick way to remove syntax errors which should never creep into your code.

However, you'll no doubt soon tire of typing "php -l" before every Git commit message, so why not let Git do the checking for you with a "pre-commit hook".

Travis Swicegood has a great article on how to set this up with Git :

I found you could pretty much copy his pre-commit PHP script and paste it into your .git/hooks directory with a couple caveats :

  • Use the mysterious commit hash '4b825dc64...' which appears in his script. It's also in the 'pre-commit.sample' which comes from Git. The mystery commit represents an empty repository commit and is not peculiar to a given repository.
  • Name your pre-commit script 'pre-commit'. Otherwise, Git won't find it.

There's a follow-up post recommending the following file pattern for Drupal :

$filename_pattern = '/\.(php|engine|theme|install|inc|module|test)$/';