Last Updated: February 25, 2016
·
2.363K
· bijanv

Static PHP code analysis with Sublime Text 2

The steps below will perform static code analysis on your PHP code (make sure there are no syntax errors, etc)

Requirements: Package Control for Sublime Text


Step 1) Add a new build system

Go to Tools->Build->New Build System and paste the following in

{
    "cmd": ["/usr/bin/php", "-l", "$file"]
}

Save it as whatever you want but keep it in the folder that it defaults to


Step 2) On save run the build

Press Command+shift+P -> type in install and select 'Package Control: Install Package' -> type in SublimeOnSaveBuild

Once it installs, go to Sublime Text 2 -> Preferences -> Package Settings -> SublimeOnSaveBuild -> Settings - User -> type in the following

{
    "filename_filter": "\\.(php)$",
    "build_on_save": 1
}

and save.

Quit and restart Sublime and every-time you save a PHP file, it will run it through the 'linter' and let you know the results.