php - 有没有办法测试 php 代码是否兼容 php < 5.3.2

标签 php unit-testing testing version

所以我在安装 php5.6.3 的情况下运行 XAMPP。但是,我正在使用 php 5.2 为在服务器上运行的网站编写一些东西。

是否有类似 PHPUnit 或 PHPCodesniffer(或在线工具)的东西可以告诉我我的部分代码是否不能在特定版本的 php 上运行(例如 php < 5.3.2)?

谢谢

最佳答案

CodeSniffer 会做:

http://github.com/wimg/PHP53Compat_CodeSniffer/downloads 下载最新版本– 确保将 PHP53Compat_CodeSniffer 目录重命名为 PHP53Compatibility 如果你有 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/

相关文章:

PHP:如何以小时:分钟:秒的形式获取当前时间?

PHP 撇号和查询字符串

javascript - react 测试 : Event handlers in React Shallow Rendering unit tests

unit-testing - 如何在 React Jest 测试中获取 "mock"navigator.geolocation

database - 我应该使用 mock 还是 dbunit 来测试访问数据库的方法?

android - 如何更改android项目平台版本

java - cucumber :循环场景中的步骤

php - Apache 安装和运行 php 文件

PHP 按位枚举

c++ - 不可实例化的谷歌测试夹具父类(super class)