PHP 5.4 compatibility checks using PHP_CodeSniffer

Update (27 Nov) : Support for PHP 5.5alpha is included.

For those of you who are new to this concept, check my blog post from a while ago. It will explain the basic concept of using PHP_CodeSniffer to automate compatibility checks. But don’t use the download links, because they point to the old (PHP 5.3) version !

What’s new ?

Quite a few things have changed in this new release :

  • There’s no version specific release anymore. The previous codesniffer standard was called PHP53Compatibility, but it seemed quite stupid to make a new standard for every PHP version out there, especially since that would keep certain people from upgrading to the latest major PHP version. So the new PHPCompatibility standard works for 5.0 – 5.4
  • But since some people simply can’t upgrade to the latest version, I added version information to all the checks. For example : the deprecated  function checker will now tell you that session_register() is deprecated since PHP 5.3 and removed since PHP 5.4 – if you’re running 5.2 and want to move to 5.3, at least you know right away that you’ll have to fix that problem, because otherwise you can’t ever upgrade to 5.4. This version check is available on deprecated/removed function, deprecated/removed php.ini directives and deprecated/removed extensions.
  • Default timezone check has been added : since PHP 5.4, you need to have a default timezone set or PHP will complain. This is ofcourse only useful if you run the tests on a system with identical settings as your production environment.
  • A check for the removed functionality on break and continue was added. (Using a variable or function call as a parameter on break and continue is no longer allowed.)
  • 2 algorithms were removed in the hash extension, so there’s a check for that as well

Where to get it

2 options :

  • Using git : run this in your PHP_CodeSniffer/Standards directory :
    ~ > git clone git:// PHPCompatibility
  • Downloading a zip : download here and unzip the file in PHP_CodeSniffer/Standards/PHPCompatibility

How to run it

Start PHP_CodeSniffer like this :

phpcs --standard=PHPCompatibility <path-to-your-PHP-source-directory>

Enjoy !

As always, any feedback (or patches on Github) welcome !

ShareFlattr the authorTweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

flattr this!

Tags: , , , , ,

15 Responses to “PHP 5.4 compatibility checks using PHP_CodeSniffer”

  1. I enjoy a lot! My compagny have a huge code base to validate for PHP 5.3, and your sniffs help us a lot. I still looking for sniffs to ensure code is compatible with 5.2 AND 5.3.
    Thanks for your help.

    • wimg says:

      This codesniffer standard will actually tell you which of the features are incompatible with which specific version (5.0, 5.1, 5.2, 5.3 or 5.4). Ofcourse, if you want to use it in a continuous integration environment, you will get errors about 5.4 even when you’re not running 5.4 yet.
      You can ofcourse always run the old PHP53Compat standard for those environments. Check the first link (pointing to my previous blog post) for that codesniffer standard, which will check for 5.3 compatibility.

  2. Matthew John says:

    Thanks for putting this together as it’s really helpful.

    I’d just like to make a note that might maybe help some people regarding the Default timezone check.

    My date.timezone was setup correctly, but I was still getting an error message. It was not until I actually sat down and had a little think, that I realized that I have 2 php.ini files. One for Apache, and one for php cli. My Apache config was correct, but my cli had no timezone configured.

  3. Julio says:

    the git repo has changed:

    git clone PHPCompatibility

  4. Fabrice says:


    I used your package, and it is really useful, so I am wondering if you could help me. I am currently looking for a specific sniffer.
    I have three big PHP project, and someone had the good idea to use the silent operator for some function calls.
    So, I would be happy if you could help me to write (or if you have one already) a sniffer to detect all function call using the silent operator.


  5. After installing PHP_CodeSniffer i try using it and got error:

    ERROR: the “PHPCompatibility” coding standard is not installed. The installed coding standards are PHPCS, PSR1, MySource, Zend, PEAR, Squiz and PSR2

    best regards


    • wimg says:

      You need to download PHPCompatibility from Github and install it in /usr/share/pear/PHP/CodeSniffer/Standards/ (in its own PHPCompatibility directory)

  6. xf- says:


    i get an error.

    ls -ls /usr/share/php/test/PHP_CodeSniffer/CodeSniffer/Standards/PHPCompatibility
    4 -rw-r–r– 1 root root 771 Mar 4 2012 README
    4 -rw-r–r– 1 root root 916 Aug 6 15:11
    4 -rw-r–r– 1 root root 167 Mar 4 2012 ruleset.xml
    4 drwxr-xr-x 3 root root 4096 Aug 6 15:11 Sniffs

    pear list | grep CodeS
    PHP_CodeSniffer 1.4.6 stable

    I tried the git and the zip.

    Message if i try to execute the tool:
    ERROR: the “PHPCompatibility” coding standard is not installed. The installed coding standards are PSR1, MySource, PHPCS, Zend, Squiz, PSR2 and PEAR

    All the best

    • wimg says:

      That looks like an odd location for the CodeSniffer. Normally it’s located in /usr/share/pear/PHP/CodeSniffer and the standard should be installed in /usr/share/pear/PHP/CodeSniffer/Standards/

  7. Suley says:

    PHP Notice: Undefined offset: 3 in /usr/share/pear/PHP/CodeSniffer.php on line 1036
    PHP Fatal error: Cannot redeclare class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff in /usr/share/pear/PHP/CodeSniffer/Standards/PHPCompatibility/Sniffs/DeprecatedIniDirectivesSniff.php on line 23

  8. Suley says:

    Sorted! correct Path must be
    before was

  9. Michael says:

    Okay so I downloaded — Version 1.5

    I need to run compatibility check for php 5.4 running wordpress. Help me see the exact steps for running this file. Thanks!

  10. Shinzo says:

    Hello and thank you for all. I have juste a probleme I think I have the solution but I prefer ask.

    I install this on my website and when I run phpCompatility I have some error like that

    Undefined property: PHPCompatibility_Sniffs_PHP_NewFunctionsSniff::$forbiddenFunctionNames
    Undefined property: PHPCompatibility_Sniffs_PHP_NewFunctionsSniff::$patternMatch

    Is there possible I see cause my phpcs version is 1.3 beta, and I must have 1.5?

    Thanks for answer

Leave a Reply