所以我在安装 php5.6.3 的情况下运行 XAMPP。但是,我正在使用 php 5.2 为在服务器上运行的网站编写一些东西。
是否有类似 PHPUnit 或 PHPCodesniffer(或在线工具)的东西可以告诉我我的部分代码是否不能在特定版本的 php 上运行(例如 php < 5.3.2)?
谢谢
最佳答案
CodeSniffer 会做:
在 http://github.com/wimg/PHP53Compat_CodeSniffer/downloads 下载最新版本– 确保将 PHP53Compat_CodeSniffer
目录重命名为 PHP53Compatibilit
y
如果你有 git,请使用:
git clone git://github.com/wimg/PHP53Compat_CodeSniffer.git PHP53Compatibility
Copy the PHP53Compatibility directory to {your pear path}/PHP/CodeSniffer/Standards
如何运行
像这样启动 PHP_CodeSniffer :
phpcs --standard=PHP53Compatibility <path-to-your-PHP-source-directory>
示例输出
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)
等...
源代码:http://techblog.wimgodden.be/2010/06/24/automated-php-5-3-compatibility-testing-for-your-old-code/
关于php - 有没有办法测试 php 代码是否兼容 php < 5.3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28698195/