monque/php-migration
Composer 安装命令:
composer require monque/php-migration
包简介
A static analyzer for PHP version migration and compatibility
README 文档
README
Readme in Chinese 中文
This is a static analyzer for PHP version migration and compatibility checking.
It can suppose your current code running under the new version of PHP then do checking, and provide advice and treatment.
And it can simplify the process of upgrading PHP. Its goal is instead of manual checking.
Features:
- Wide coverage, checks most of the changes which introduced in PHP 5.3 - 7.0.
- Strict, without missing any risk.
- Zero configuration, run directly after download.
- Simply add custom checks.
Compare to the similar project PHP Compatibility
PHP Compatibilityis a set of sniffs forPHP_CodeSniffer, therefore it lacks flexibility and can not checks more changes. just objective comparison
Notice: this project is in beta stage, feel free to report any issues.
Install / Usage
-
You can download a executable Phar file
wget https://github.com/monque/PHP-Migration/releases/download/v0.2.2/phpmig.phar -
Use the following command to check PHP file
php phpmig.phar sample.phpSuppose these code stored in
sample.php<?php // Fatal error: Only variables can be passed by reference array_shift(array(1, 2)); sort(array(1, 2, 3)); // __DIR__ is pre-defined define('__DIR__', dirname(__FILE__)); // Fatal error: Cannot redeclare class_alias() function class_alias() {} // This is fine if (!function_exists('class_alias')) { function class_alias() {} } // Fatal error: Call-time pass-by-reference has been removed array_map('trim', &$_SERVER); // Fatal error: 'break' operator with non-constant operand is no longer supported while (true) { break $a; } // Fatal error: Cannot re-assign auto-global variable _GET function ohno($_GET) {} // Array keys won't be overwritten when defining an array as a property of a class via an array literal class C { const ONE = 1; public $array = [ self::ONE => 'foo', 'bar', 'quux', ]; } // set_exception_handler() is no longer guaranteed to receive Exception objects set_exception_handler(function (Exception $e) { }); // Changes to the handling of indirect variables, properties, and methods echo $$foo['bar']['baz']; // foreach no longer changes the internal array pointer foreach ($list as &$row) { current($list); }
-
Output report Each columns means: Line Number, Level, Identified, Version, Message
File: sample.php -------------------------------------------------------------------------------- Found 11 spot(s), 10 identified -------------------------------------------------------------------------------- 3 | FATAL | * | 5.3.0 | Only variables can be passed by reference 4 | FATAL | * | 5.3.0 | Only variables can be passed by reference 7 | WARNING | * | 5.3.0 | Constant "__DIR__" already defined 10 | FATAL | * | 5.3.0 | Cannot redeclare class_alias() 18 | FATAL | * | 5.4.0 | Call-time pass-by-reference has been removed 22 | FATAL | * | 5.4.0 | break operator with non-constant operand is no longer supported 26 | FATAL | * | 5.4.0 | Cannot re-assign auto-global variable 31 | WARNING | | 5.6.0 | Array key may be overwritten when defining as a property and using constants 39 | WARNING | * | 7.0.0 | set_exception_handler() is no longer guaranteed to receive Exception objects 42 | WARNING | * | 7.0.0 | Different behavior between PHP 5/7 46 | NOTICE | * | 7.0.0 | foreach no longer changes the internal array pointer --------------------------------------------------------------------------------The third field
Identifiedwill be explained at bottom.
Set Selection
A Checking Set contains muiltiple Check Class, and the dependence of Set can be specified.
List all sets through command php phpmig.phar -l.
classtree => List contents of classes in a tree-like format
to53 => Migrating from ANY version to PHP 5.3.x
to54 => Migrating from ANY version to PHP 5.4.x
to55 => Migrating from ANY version to PHP 5.5.x
to56 => Migrating from ANY version to PHP 5.6.x
to70 => Migrating from ANY version to PHP 7.0.x
v53 => Migrating from PHP 5.2.x to PHP 5.3.x
v54 => Migrating from PHP 5.3.x to PHP 5.4.x
v55 => Migrating from PHP 5.4.x to PHP 5.5.x
v56 => Migrating from PHP 5.5.x to PHP 5.6.x
v70 => Migrating from PHP 5.6.x to PHP 7.0.x
And add param -s like php phpmig.phar -s <setname> to select a set to use.
Utility, print class tree
Like the common linux command tree, the following command will scan files and
output all classes in a tree-like format.
php phpmig.phar -s classtree .
Output:
|-- PhpMigration\App
|-- PhpMigration\Changes\AbstractChange
| |-- PhpMigration\Changes\AbstractIntroduced
| | |-- PhpMigration\Changes\v5dot3\Introduced
| | |-- PhpMigration\Changes\v5dot4\Introduced
| | |-- PhpMigration\Changes\v5dot5\Introduced
| | |-- PhpMigration\Changes\v5dot6\Introduced
| | `-- PhpMigration\Changes\v7dot0\Introduced
| |-- PhpMigration\Changes\AbstractKeywordReserved
| | |-- PhpMigration\Changes\v5dot3\IncompReserved
| | `-- PhpMigration\Changes\v5dot4\IncompReserved
| |-- PhpMigration\Changes\AbstractRemoved
| | |-- PhpMigration\Changes\v5dot3\Removed
| | |-- PhpMigration\Changes\v5dot4\Removed
| | |-- PhpMigration\Changes\v5dot5\Removed
| | |-- PhpMigration\Changes\v5dot6\Removed
| | `-- PhpMigration\Changes\v7dot0\Removed
| |-- PhpMigration\Changes\ClassTree
| |-- PhpMigration\Changes\Dev
| |-- PhpMigration\Changes\v5dot3\Deprecated
| |-- PhpMigration\Changes\v5dot3\IncompByReference
| |-- PhpMigration\Changes\v5dot3\IncompCallFromGlobal
| |-- PhpMigration\Changes\v5dot3\IncompMagic
| |-- PhpMigration\Changes\v5dot3\IncompMagicInvoked
| |-- PhpMigration\Changes\v5dot3\IncompMisc
| |-- PhpMigration\Changes\v5dot4\Deprecated
| |-- PhpMigration\Changes\v5dot4\IncompBreakContinue
| |-- PhpMigration\Changes\v5dot4\IncompByReference
| |-- PhpMigration\Changes\v5dot4\IncompHashAlgo
| |-- PhpMigration\Changes\v5dot4\IncompMisc
| |-- PhpMigration\Changes\v5dot4\IncompParamName
| |-- PhpMigration\Changes\v5dot4\IncompRegister
| |-- PhpMigration\Changes\v5dot5\Deprecated
| |-- PhpMigration\Changes\v5dot5\IncompCaseInsensitive
| |-- PhpMigration\Changes\v5dot5\IncompPack
| |-- PhpMigration\Changes\v5dot6\Deprecated
| |-- PhpMigration\Changes\v5dot6\IncompMisc
| |-- PhpMigration\Changes\v5dot6\IncompPropertyArray
| |-- PhpMigration\Changes\v7dot0\Deprecated
| |-- PhpMigration\Changes\v7dot0\ExceptionHandle
| |-- PhpMigration\Changes\v7dot0\ForeachLoop
| |-- PhpMigration\Changes\v7dot0\FuncList
| |-- PhpMigration\Changes\v7dot0\FuncParameters
| |-- PhpMigration\Changes\v7dot0\IntegerOperation
| |-- PhpMigration\Changes\v7dot0\KeywordReserved
| |-- PhpMigration\Changes\v7dot0\ParseDifference
| |-- PhpMigration\Changes\v7dot0\StringOperation
| `-- PhpMigration\Changes\v7dot0\SwitchMultipleDefaults
|-- PhpMigration\CheckVisitor
|-- PhpMigration\Logger
|-- PhpMigration\ReduceVisitor
|-- PhpMigration\SymbolTable
|-- PhpMigration\Utils\FunctionListExporter
|-- PhpMigration\Utils\Logging
|-- PhpMigration\Utils\Packager
`-- PhpMigration\Utils\ParserHelper
Manual Installation from Source
-
Clone this project to your local path
git clone https://github.com/monque/PHP-Migration.git php-migration cd php-migration -
Using Composer to install dependencies
curl -sS https://getcomposer.org/installer | php php composer.phar install -
Verify it works
php bin/phpmig
Explaination
Process Flow
About the third field Identified in outputing
To be honest, not all code will be checked accurately as you expect.
Some changes will never be checked accurately, and it's has nothing to do with someone's ability or technology.
For example, unpack() changes in PHP
5.5,
it now keeps trailing NULL bytes when the "a" format code is used.
Code below:
<?php unpack($obj->getFormat(), $data); // OMG, What is $obj? How getFormat() works? unpack('b3', $data); // Works in new version unpack('a3', $data); // Affected
But we can guess the value of variables, and make a level table:
| Level | Identified | Output |
|---|---|---|
| MUST affect | Yes | Yes |
| MUST NOT affect | Yes | No |
| MAY affect | No | Yes |
So, finally output
--------------------------------------------------------------------------------
Found 2 spot(s), 1 identified
--------------------------------------------------------------------------------
2 | WARNING | | 5.5.0 | Behavior of pack() with "a", "A" in format is changed
4 | WARNING | * | 5.5.0 | Behavior of pack() with "a", "A" in format is changed
--------------------------------------------------------------------------------
License
This project is released under the MIT license.
monque/php-migration 适用场景与选型建议
monque/php-migration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 592 次下载、GitHub Stars 达 204, 最近一次更新时间为 2014 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「version」 「migration」 「analyzer」 「compatibility」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 monque/php-migration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monque/php-migration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 monque/php-migration 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log analyzer widget for yii2
Versioning behaviour for eloquent models
Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.
Phan plugins for Miraheze
Display a version number
统计信息
- 总下载量: 592
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 206
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-27