Run PHP Lint before committing to GIT

This is going to sound stupid, but if you don’t have rock solid unit tests in place, one of the things you should be doing is running PHP Lint.

What is PHP Lint?
Simply stated, it checks your php file for syntax errors. How many times have you forgotten a semi-colon, or had unmatched curly braces?

How do I run PHP Lint?
It is very easy to run from the command line
php -l your_php_file.php

Using GIT? You should setup a pre-commit hook to always do this so you don’t push something bad into the repo. I am guilty of doing this in the past. 🙁

Here is a great post by Travis Swicegood about setting this up.
http://phpadvent.org/2008/dont-commit-that-error-by-travis-swicegood

One thing to remember is that you also have to make the script executable.
chmod 744 .git/hooks/pre-commit

 
TrackBack URI

1 Comment so far »

  1. Luiz Lopes said

    am March 5 2012 @ 9:08 pm

    There is that, or if you are using vim or sublime text 2, you can run lint on save.

    http://vim.wikia.com/wiki/Runtime_syntax_check_for_php
    https://github.com/Kronuz/SublimeLinter

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: