{"id":13505136,"url":"https://github.com/monque/PHP-Migration","last_synced_at":"2025-03-29T23:31:10.586Z","repository":{"id":57019463,"uuid":"25632852","full_name":"monque/PHP-Migration","owner":"monque","description":"A static analyzer for PHP version migration","archived":false,"fork":false,"pushed_at":"2018-07-20T08:39:48.000Z","size":341,"stargazers_count":202,"open_issues_count":4,"forks_count":18,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-22T23:29:20.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-23T11:06:25.000Z","updated_at":"2024-11-07T20:14:57.000Z","dependencies_parsed_at":"2022-08-22T20:31:09.760Z","dependency_job_id":null,"html_url":"https://github.com/monque/PHP-Migration","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monque%2FPHP-Migration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monque%2FPHP-Migration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monque%2FPHP-Migration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monque%2FPHP-Migration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monque","download_url":"https://codeload.github.com/monque/PHP-Migration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246258884,"owners_count":20748573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T00:00:59.202Z","updated_at":"2025-03-29T23:31:09.826Z","avatar_url":"https://github.com/monque.png","language":"PHP","readme":"# PHP Migration\n\n\u003e Readme in [Chinese 中文](https://github.com/monque/PHP-Migration/tree/master/README_ZH.md)\n\n[![Build Status](https://travis-ci.org/monque/PHP-Migration.svg)](https://travis-ci.org/monque/PHP-Migration)\n[![Total Downloads](https://poser.pugx.org/monque/PHP-Migration/d/total.svg)](https://packagist.org/packages/monque/PHP-Migration)\n[![Latest Stable Version](https://poser.pugx.org/monque/PHP-Migration/v/stable.svg)](https://packagist.org/packages/monque/PHP-Migration)\n[![License](https://poser.pugx.org/monque/PHP-Migration/license.svg)](https://packagist.org/packages/monque/PHP-Migration)\n\nThis is a static analyzer for PHP version migration and compatibility checking.\n\nIt can suppose your current code running under the new version of PHP then do\nchecking, and provide advice and treatment.\n\nAnd it can simplify the process of upgrading PHP. Its goal is instead of manual\nchecking.\n\nFeatures:\n- Wide coverage, checks most of the changes which introduced in PHP 5.3 - 7.0.\n- Strict, without missing any risk.\n- Zero configuration, run directly after download.\n- Simply add custom checks.\n\n\u003e Compare to the similar project [PHP Compatibility](https://github.com/wimg/PHPCompatibility)\n\u003e `PHP Compatibility` is a set of sniffs for `PHP_CodeSniffer`, therefore it\n\u003e lacks flexibility and can not checks more changes.\n\u003e *just objective comparison*\n\n**Notice: this project is in beta stage, feel free to report any issues.**\n\n\n## Install / Usage\n\n1. You can download a executable [Phar](http://php.net/manual/en/book.phar.php) file\n    ```\n    wget https://github.com/monque/PHP-Migration/releases/download/v0.2.2/phpmig.phar\n    ```\n\n2. Use the following command to check PHP file\n    ```\n    php phpmig.phar sample.php\n    ```\n\n    Suppose these code stored in `sample.php`\n    ``` php\n    \u003c?php\n    // Fatal error: Only variables can be passed by reference\n    array_shift(array(1, 2));\n    sort(array(1, 2, 3));\n\n    // __DIR__ is pre-defined\n    define('__DIR__', dirname(__FILE__));\n\n    // Fatal error: Cannot redeclare class_alias()\n    function class_alias() {}\n\n    // This is fine\n    if (!function_exists('class_alias')) {\n        function class_alias() {}\n    }\n\n    // Fatal error: Call-time pass-by-reference has been removed\n    array_map('trim', \u0026$_SERVER);\n\n    // Fatal error: 'break' operator with non-constant operand is no longer supported\n    while (true) {\n        break $a;\n    }\n\n    // Fatal error: Cannot re-assign auto-global variable _GET\n    function ohno($_GET) {}\n\n    // Array keys won't be overwritten when defining an array as a property of a class via an array literal\n    class C {\n        const ONE = 1;\n        public $array = [\n            self::ONE =\u003e 'foo',\n            'bar',\n            'quux',\n        ];\n    }\n\n    // set_exception_handler() is no longer guaranteed to receive Exception objects\n    set_exception_handler(function (Exception $e) { });\n\n    // Changes to the handling of indirect variables, properties, and methods\n    echo $$foo['bar']['baz'];\n\n    // foreach no longer changes the internal array pointer\n    foreach ($list as \u0026$row) {\n        current($list);\n    }\n    ```\n\n3. Output report\n    Each columns means: Line Number, Level, Identified, Version, Message\n    ```\n    File: sample.php\n    --------------------------------------------------------------------------------\n\tFound 11 spot(s), 10 identified\n\t--------------------------------------------------------------------------------\n        3 | FATAL      | * | 5.3.0 | Only variables can be passed by reference\n        4 | FATAL      | * | 5.3.0 | Only variables can be passed by reference\n        7 | WARNING    | * | 5.3.0 | Constant \"__DIR__\" already defined\n       10 | FATAL      | * | 5.3.0 | Cannot redeclare class_alias()\n       18 | FATAL      | * | 5.4.0 | Call-time pass-by-reference has been removed\n       22 | FATAL      | * | 5.4.0 | break operator with non-constant operand is no longer supported\n       26 | FATAL      | * | 5.4.0 | Cannot re-assign auto-global variable\n       31 | WARNING    |   | 5.6.0 | Array key may be overwritten when defining as a property and using constants\n       39 | WARNING    | * | 7.0.0 | set_exception_handler() is no longer guaranteed to receive Exception objects\n       42 | WARNING    | * | 7.0.0 | Different behavior between PHP 5/7\n       46 | NOTICE     | * | 7.0.0 | foreach no longer changes the internal array pointer\n    --------------------------------------------------------------------------------\n    ```\n    \u003e The third field `Identified` will be explained at bottom.\n\n\n### Set Selection\n\nA Checking Set contains muiltiple Check Class, and the dependence of Set can be\nspecified.\n\nList all sets through command `php phpmig.phar -l`.\n\n```\nclasstree  =\u003e List contents of classes in a tree-like format\nto53       =\u003e Migrating from ANY version to PHP 5.3.x\nto54       =\u003e Migrating from ANY version to PHP 5.4.x\nto55       =\u003e Migrating from ANY version to PHP 5.5.x\nto56       =\u003e Migrating from ANY version to PHP 5.6.x\nto70       =\u003e Migrating from ANY version to PHP 7.0.x\nv53        =\u003e Migrating from PHP 5.2.x to PHP 5.3.x\nv54        =\u003e Migrating from PHP 5.3.x to PHP 5.4.x\nv55        =\u003e Migrating from PHP 5.4.x to PHP 5.5.x\nv56        =\u003e Migrating from PHP 5.5.x to PHP 5.6.x\nv70        =\u003e Migrating from PHP 5.6.x to PHP 7.0.x\n```\n\nAnd add param `-s` like `php phpmig.phar -s \u003csetname\u003e` to select a set to use.\n\n\n### Utility, print class tree\n\nLike the common linux command `tree`, the following command will scan files and\noutput all classes in a tree-like format.\n```\nphp phpmig.phar -s classtree .\n```\n\nOutput:\n```\n|-- PhpMigration\\App\n|-- PhpMigration\\Changes\\AbstractChange\n|   |-- PhpMigration\\Changes\\AbstractIntroduced\n|   |   |-- PhpMigration\\Changes\\v5dot3\\Introduced\n|   |   |-- PhpMigration\\Changes\\v5dot4\\Introduced\n|   |   |-- PhpMigration\\Changes\\v5dot5\\Introduced\n|   |   |-- PhpMigration\\Changes\\v5dot6\\Introduced\n|   |   `-- PhpMigration\\Changes\\v7dot0\\Introduced\n|   |-- PhpMigration\\Changes\\AbstractKeywordReserved\n|   |   |-- PhpMigration\\Changes\\v5dot3\\IncompReserved\n|   |   `-- PhpMigration\\Changes\\v5dot4\\IncompReserved\n|   |-- PhpMigration\\Changes\\AbstractRemoved\n|   |   |-- PhpMigration\\Changes\\v5dot3\\Removed\n|   |   |-- PhpMigration\\Changes\\v5dot4\\Removed\n|   |   |-- PhpMigration\\Changes\\v5dot5\\Removed\n|   |   |-- PhpMigration\\Changes\\v5dot6\\Removed\n|   |   `-- PhpMigration\\Changes\\v7dot0\\Removed\n|   |-- PhpMigration\\Changes\\ClassTree\n|   |-- PhpMigration\\Changes\\Dev\n|   |-- PhpMigration\\Changes\\v5dot3\\Deprecated\n|   |-- PhpMigration\\Changes\\v5dot3\\IncompByReference\n|   |-- PhpMigration\\Changes\\v5dot3\\IncompCallFromGlobal\n|   |-- PhpMigration\\Changes\\v5dot3\\IncompMagic\n|   |-- PhpMigration\\Changes\\v5dot3\\IncompMagicInvoked\n|   |-- PhpMigration\\Changes\\v5dot3\\IncompMisc\n|   |-- PhpMigration\\Changes\\v5dot4\\Deprecated\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompBreakContinue\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompByReference\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompHashAlgo\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompMisc\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompParamName\n|   |-- PhpMigration\\Changes\\v5dot4\\IncompRegister\n|   |-- PhpMigration\\Changes\\v5dot5\\Deprecated\n|   |-- PhpMigration\\Changes\\v5dot5\\IncompCaseInsensitive\n|   |-- PhpMigration\\Changes\\v5dot5\\IncompPack\n|   |-- PhpMigration\\Changes\\v5dot6\\Deprecated\n|   |-- PhpMigration\\Changes\\v5dot6\\IncompMisc\n|   |-- PhpMigration\\Changes\\v5dot6\\IncompPropertyArray\n|   |-- PhpMigration\\Changes\\v7dot0\\Deprecated\n|   |-- PhpMigration\\Changes\\v7dot0\\ExceptionHandle\n|   |-- PhpMigration\\Changes\\v7dot0\\ForeachLoop\n|   |-- PhpMigration\\Changes\\v7dot0\\FuncList\n|   |-- PhpMigration\\Changes\\v7dot0\\FuncParameters\n|   |-- PhpMigration\\Changes\\v7dot0\\IntegerOperation\n|   |-- PhpMigration\\Changes\\v7dot0\\KeywordReserved\n|   |-- PhpMigration\\Changes\\v7dot0\\ParseDifference\n|   |-- PhpMigration\\Changes\\v7dot0\\StringOperation\n|   `-- PhpMigration\\Changes\\v7dot0\\SwitchMultipleDefaults\n|-- PhpMigration\\CheckVisitor\n|-- PhpMigration\\Logger\n|-- PhpMigration\\ReduceVisitor\n|-- PhpMigration\\SymbolTable\n|-- PhpMigration\\Utils\\FunctionListExporter\n|-- PhpMigration\\Utils\\Logging\n|-- PhpMigration\\Utils\\Packager\n`-- PhpMigration\\Utils\\ParserHelper\n```\n\n### Manual Installation from Source\n\n1. Clone this project to your local path\n    ```\n    git clone https://github.com/monque/PHP-Migration.git php-migration\n    cd php-migration\n    ```\n\n2. Using [Composer](https://getcomposer.org/download/) to install dependencies\n    ```\n    curl -sS https://getcomposer.org/installer | php\n    php composer.phar install\n    ```\n\n3. Verify it works\n    ```\n    php bin/phpmig\n    ```\n\n\n## Explaination\n\n### Process Flow\n\n![flow](http://p9.qhimg.com/t010392c0d7e3e01882.png)\n\n### About the third field `Identified` in outputing\n\nTo be honest, not all code will be checked accurately as you expect.\n\nSome changes will never be checked accurately, and it's has nothing to do with\nsomeone's ability or technology.\n\nFor example, [`unpack()` changes in PHP\n5.5](http://php.net/manual/en/migration55.incompatible.php#migration55.incompatible.pack),\nit now keeps trailing NULL bytes when the \"a\" format code is used.\n\nCode below:\n``` php\n\u003c?php\nunpack($obj-\u003egetFormat(), $data); // OMG, What is $obj? How getFormat() works?\nunpack('b3', $data); // Works in new version\nunpack('a3', $data); // Affected\n```\n\nBut we can guess the value of variables, and make a level table:\n\n| Level | Identified | Output |\n| ---- | ---- | ---- |\n| MUST affect | Yes | Yes |\n| MUST NOT affect | Yes | No |\n| MAY  affect | No | Yes |\n\nSo, finally output\n```\n--------------------------------------------------------------------------------\nFound 2 spot(s), 1 identified\n--------------------------------------------------------------------------------\n   2 | WARNING    |   | 5.5.0 | Behavior of pack() with \"a\", \"A\" in format is changed\n   4 | WARNING    | * | 5.5.0 | Behavior of pack() with \"a\", \"A\" in format is changed\n--------------------------------------------------------------------------------\n```\n\n\n## License\nThis project is released under the [MIT license](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Standalone","PHP","目录","Table of Contents"],"sub_categories":["Compatibility","静态分析 Static Analysis","Static Analysis"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonque%2FPHP-Migration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonque%2FPHP-Migration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonque%2FPHP-Migration/lists"}