Reputation: 467
So I'm running XAMPP with php5.6.3 installed. However, I'm writing something for a website running on a server using php 5.2.
Is there anything like PHPUnit or PHPCodesniffer (or an online tool) which will tell me if part of my code won't work on specific versions of php (such as php < 5.3.2)?
Thanks
Upvotes: 1
Views: 2135
Reputation: 467
Ok. So after looking into all of the above suggestions I've settled on PHPCompatibility by Wim Godden. https://github.com/wimg/PHPCompatibility
Two reasons I chose this over PHP53Compat_CodeSniffer is:
You can also test for backwards compatibility of your code by specifying versions like 5.2, which causes it to check whether you’re using functions or keywords not known to this older version. Quite nice if you’re coding on PHP 5.5, but your system engineer tells you half way through the project the project will have to be deployed on 5.2.
That's exactly my case. And...
Upvotes: 1
Reputation: 98901
CodeSniffer will do:
Download the latest release at http://github.com/wimg/PHP53Compat_CodeSniffer/downloads – make sure you rename the PHP53Compat_CodeSniffer
directory to PHP53Compatibilit
y
If you have git, use :
git clone git://github.com/wimg/PHP53Compat_CodeSniffer.git PHP53Compatibility
Copy the PHP53Compatibility directory to {your pear path}/PHP/CodeSniffer/Standards
How to run
Start PHP_CodeSniffer like this :
phpcs --standard=PHP53Compatibility <path-to-your-PHP-source-directory>
Sample output
FILE: C:\temp\bla.php
--------------------------------------------------------------------------------
FOUND 15 ERROR(S) AND 2 WARNING(S) AFFECTING 12 LINE(S)
--------------------------------------------------------------------------------
4 | ERROR | Function name, class name, namespace name or constant name can
| | not be reserved keyword 'goto' (since version 5.3)
6 | ERROR | Extension 'dbase' is not available in PHP 5.3 anymore
12 | ERROR | Function name, class name, namespace name or constant name can
| | not be reserved keyword 'const' (since version all)
12 | ERROR | Function name, class name, namespace name or constant name can
| | not be reserved keyword 'const' (since version all)
etc...
SRC: http://techblog.wimgodden.be/2010/06/24/automated-php-5-3-compatibility-testing-for-your-old-code/
Upvotes: 1