php7cc is a command line tool designed to make migration from PHP 5.3-5.6 to PHP 7 easier. It searches for potentially troublesome statements in existing code and generates reports containing file names, line numbers and short problem descriptions. It does not automatically fix code to work with the new PHP version.
It tries to find statements that change their behaviour or lead to fatal errors in PHP 7. A list of such statements can be found in php-src repository. Although php7cc tries to detect as much problems as accurately as possible, sometimes 100% reliable detection is very hard to achieve. That's why you should also run a comprehensive test suite for the code you are going to migrate.
To run php7cc, you need php installed, minimum required version is 5.3.3. PHP 7 is supported, but files with syntax errors (for example, invalid numeric literals or invalid UTF-8 codepoint escape sequences) can't be processed. You will only get the warning message about the first syntax error for such files.
You may also need composer to install php7cc.
You can download a phar package for any stable version from the Github releases page.
Make sure you have composer installed. Then execute the following command:
composer global require sstalle/php7cc
It is also recommended to add ~/.composer/vendor/bin
to your PATH
environment
variable:
export PATH="$PATH:$HOME/.composer/vendor/bin"
This makes it possible to run php7cc by entering just the executable name.
Make sure you have composer installed. Then execute the following command from your project directory:
composer require sstalle/php7cc --dev
Examples in this section assume that you have installed php7cc globally using composer
and that you have added it's vendor binaries directory to your PATH
. If this is not
the case, just substitute php7cc
with the correct path to the binary of phar package.
For local per project installation the executable will be located at <your_project_path>/vendor/bin/php7cc
.
To see the full list of available options, run:
php7cc --help
To check a file or a directory, pass its name as the first argument. Directories are checked recursively.
So, to check a file you could run:
php7cc /path/to/my/file.php
To check a directory:
php7cc /path/to/my/directory/
When checking a directory, you can also specify a comma-separated list of file extensions that should be checked. By default, only .php files are processed.
For example, if you want to check .php, .inc and .lib files, you could run:
php7cc --extensions=php,inc,lib /path/to/my/directory/
You can specify a list of absolute or relative paths to exclude from checking. Relative paths are relative to the checked directories.
So, if you want to exclude vendor and test directories, you could run:
php7cc --except=vendor --except=/path/to/my/directory/test /path/to/my/directory/
In this example, directories /path/to/my/directory/vendor
, /path/to/my/directory/test
and their contents will not be checked.
You should increase maximum function nesting level in your PHP or Xdebug config file like this:
xdebug.max_nesting_level = 1000
Please read the contributing guidelines.
The list of contributors is available on the corresponding Github page.