The Eclipse PHP Codesniffer tool for Eclipse allows you to detect coding standards errors as you are actually typing your code. Unfortunately, not everyone realises this and sets it up simply to output the errors to the console. Here, I will show you how to setup PHP Codesniffer to work natively in Eclipse.
You will need a copy of PHP installed and running on your machine to make this work.
1) Install PHP Codesniffer in Eclipse
Follow these instructions to install PHP Codesniffer in Eclipse.
Zend Studio Users: Please note that if you are using the Zend Studio version of Eclipse, you will need to go to “Help > Software Updates > Search for new feature to install > Find & Install…” then you will need to add a new source by clicking on “Add Remote Site…”.
- Setup PHP Codesniffer in Eclipse
- URL to use for “Install new Software” in Eclipse: http://www.phpsrc.org/eclipse/pti/
- Restart Eclipse
However, it probably won’t work straight away, because you need to set-up your PHP executables in Eclipse.
2) Setup PHP Executables in Eclipse
Navigate to “Window > Preferences > PHP > PHP Executables” and if there is nothing in the list, then add a new one that points to your PHP executable.
3) PHP Codesniffer Settings
Now all we need to do is setup PHP Codesniffer in the Eclipse preferences settings.
Goto “Window > Preferences > PHP Tools > Codesniffer”.
- PHP Executable:
Select the one that you wish to use. You might have created one in the step above? - Codesniffer Standards:
Select the one you prefer, I use Zend. - Standard Tab Width:
Please ensure this is correct to your coding standard, I set it to 4. - File Extensions:
This is a comma separated list of file extensions that PHPCS will try and validate. I only have php in my list. You may have some “.inc” files. Don’t allow it to validate Zend View “.phtml” files. If you allow it to validate .phtml files, it will show that all of your Zend View files are invalid as they contain HTML.
It will ask you if you want to do a “Full Rebuild” – you need to answer yes to this. Depending on the size of your codebase it could take a while to do this, so please be patient.
All done!
Once your rebuild is complete, Eclipse will now show you the files that have coding standards errors with a little red cross next to them. Furthermore, when you open the file, it will show you where the errors are down the left-hand side next to the line number.
Tip: Eclipse Settings
I use Zend Framework coding standards, mainly because I use it every day. I find it eaiser if my development environment is setup correctly. These are my Eclipse settings, feel free to use them:
- Click Window > Preferences
- General > Editors > Text Editors
- Set Displaid tab width to 4
- Tick Insert spaces for tabs
- Tick Show Print Margin
- Set Print Margin Column to 120
- General > Perspectives
- Select PHP and click Make Default
- General > Workspace
- Set Text File Encoding to UTF-8
- Set New Text File Delimiter to Unix
- PHP > Code Style > Formatter
- Set Tab Policy to Spaces
- Set Indentation size to 4
- PHP > Editor > Save Actions
- Tick Remove trailing whitespace
- Check All Lines
If you have any comments, please feel free to share them below.
Permalink: http://www.websitefactors.co.uk/other/2011/10/installing-php-codesniffer-properly-in-eclipse/

Hi,
I have just installed PHPCS in Eclipse (Yoxos distro with PHP extension), and if it take a huge amount of time on huge project, it run fine and help a lot.
Thanks!
Cédric
Yeah, the extension can take some time to complete for the first time. Though I believe that after this phpcs is only run on file save or periodically during file auto-save – so it’s very fast (unless you have a massive file or a very slow machine).
funny I kept getting this:
Cannot complete the install because one or more required items could not be found. Software being installed: PHP Tool Integration Core
Hmm – that’s odd. Are you using the lastest version of Eclipse? The above was tested using the standard distribution of Eclipse PDT.
@Peter eman abastillas
A colleague of mine had a similar problem to this today. They installed eclipse using the standard distribution, not the PDT version. They then tried to install the PHP PTI tools. They recieved the same message you specify above.
The reason was that they had not installed the PHP development tools in their Eclipse.
Explanation:
Eclipse comes in many flavours. For the purposes of this explanation, there is Standard Eclipse and Eclipse PDT. My colleague installed the Standard Eclipse. If you do this and would like to use any PHP tools, you need to install PHP Development Tools on-top of your Eclipse installation.
Once you have done this, you can install the PTI tools as demonstrated above.
Note: The Eclipse PDT package comes with PHP Development Tools included and you do not need to do this, PHP PTI tools should install correctly.