Skip to content

Static analysis tools for PHP version compatibility

Before a PHP version is updated on a WordPress VIP Platform environment, all PHP files in an application’s GitHub repository should be scanned for potential incompatibility issues, and the identified issues should be resolved.

PHPCS scans are useful for identifying many incompatibilities with a higher version of PHP that exist in application code. However, there are some runtime changes that PHPCS is not designed to identify.

PHPStanPsalm, and other static analysis tools typically have rule levels that allow fixing the lowest level issues first, and then gradually integrating the tool further to improve the quality of a codebase.

To be most effective, a codebase should include type declarations and the strict_types=1 declaration, or be correctly documented (@param and @return lines in DocBlocks).

Static analysis tools are useful for highlighting code that passes unexpected types into functions. These types of operations can cause fatal TypeError exceptions to be thrown.

To allow these tools to understand the functions defined in WordPress core, install packages such as phpstan-wordpress and psalm-plugin-wordpress.

Suppressing TypeError exceptions by using try-catch blocks or typecasting is strongly discouraged. Taking the time to fix the root cause of issues will produce stronger, less brittle and error-prone code.

Last updated: December 22, 2023

Relevant to

  • WordPress