Title: Static analysis tools for PHP version compatibility
Author: WordPress VIP Documentation
Published: September 19, 2023
Last modified: December 22, 2023

---

 1. [WordPress on VIP](https://docs.wpvip.com/wordpress-on-vip/)
 2. [PHP](https://docs.wpvip.com/wordpress-on-vip/php/)
 3. [Version updates for PHP](https://docs.wpvip.com/wordpress-on-vip/php/versions/)
 4. Static analysis tools for PHP version compatibility

#  Static analysis tools for PHP version compatibility

Before a PHP version is updated on a [WordPress VIP Platform environment](https://docs.wpvip.com/vip-platform/environments/),
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.

[PHPStan](https://phpstan.org/), [Psalm](https://psalm.dev/), 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](https://github.com/szepeviktor/phpstan-wordpress)
and [psalm-plugin-wordpress](https://github.com/humanmade/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