Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

php7cc

> 编程语言
Open source

PHP 7 Compatibility Checker

1.5K stars0 likes1 views
WebsiteGitHub

About

PHP 7 Compatibility Checker

PHP 7 Compatibility Checker(php7cc)

Project status

The project is no longer supported. Please consider using one of the following alternatives:

  • phan
  • phpstan

Introduction

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.

What kind of problems does it detect?

There are 2 types of issues reported by php7cc:

  1. Errors that will definitely cause some kind of trouble (a fatal, a syntax error, a notice, etc.) on PHP 7. These are highlighted in red.
  2. Warnings that may or may not lead to logical errors. For example, statements that are legal in both PHP 5 and PHP 7, but change their behaviour between versions fall into this category. Warnings are highlighted in yellow.

A list of statements that may cause errors or warnings to be reported can be found in the 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.

Prerequisites

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.

Installation

Phar package

You can download a phar package for any stable version from the Github releases page.

Composer (globally)

Make sure you have composer installed. Then execute the following command:

composer global require sstalle/php7cc

It is also recommended to add global Composer binaries directory to your PATH environment variable. The location of this directory depends on the operating system you use (see Composer documentation if you want to know more). The following command should work for some *nix systems:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

This makes it possible to run php7cc by entering just the executable name.

Composer (locally, per project)

Make sure you have composer installed. Then execute the following command from your project directory:

composer require sstalle/php7cc --dev

Docker image

A docker image is available on Docker Hub (contributed and maintained by ypereirareis).

Usage

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.

Getting help

To see the full list of available options, run:

php7cc --help

Checking a single file or directory

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/

Specifying file extensions to check

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/

Excluding file or directories

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.

Specifying minimum issue level

If you set a minimum issue level, only issues having that or higher severity level will be reported by php7cc. There are 3 issue levels: "info", "warning" and "error". "info" is reserved for future use and is the same as "warning".

Example usage:

php7cc --level=error /path/to/my/directory/

Only errors, but not warnings will be shown in this case.

Specifying output format

There are two output format available: plain and json.

output-format command-line option, o in short form, can be used in order to change the output format:

php7cc -o json /path/to/my/directory/ | json_pp

Would output:

…

Troubleshooting

Maximum function nesting level of 100/250/N reached, aborting!

You should increase maximum function nesting level in your PHP or Xdebug config file like this:

xdebug.max_nesting_level = 1000

Allowed memory size of N bytes exhausted

You should increase amount of memory available to CLI PHP scripts or disable PHP memory limit. The latter can be done by setting the memory_limit PHP option to -1. This option can be set by editing php.ini or by passing a command-line argument to PHP executable like this:

php -d memory_limit=-1 php7cc.php /path/to/my/directory

Other useful links

Contributing

Please read the contributing guidelines.

Credits

The list of contributors is available on the corresponding Github page.

GitHub Issues· 21 open

View all on GitHub
  • #149

    Should "does not cause an error in PHP 7" be an warning?

    Updated Sep 18, 2020
  • #148

    Error without a file: [Error] file_get_contents(): Filename cannot be empty. Processing aborted.

    Updated Oct 25, 2018
  • #147

    [Warning] "yield" usage in expression context

    Updated Oct 25, 2018
  • #146

    PHP nullable typehinting not supported now

    Updated Jul 1, 2018
  • #145

    Unquoted string as index or general not detected

    Updated May 16, 2018
  • #144

    space between = and & fools the checker where =& would be caught

    Updated Apr 6, 2018
  • #92

    Setting error level isn't adhered to.

    Updated Mar 19, 2018
  • #102

    Return non-zero exit codes

    Updated Feb 14, 2018
  • #142

    Unhelpful "Closing delimiter foo not found" message

    Updated Dec 10, 2017
  • #112

    Class/trait/interface "{ClassName}" was added in the global namespace.

    Updated Nov 10, 2017

Highlights

  • •PHP

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言