Checking Magento 2 Custom Code for PHP Version Compatibility
๐งช Checking Magento 2 Custom Code for PHP 8.2 Compatibility
As of Magento 2.4.6+, core support for PHP 8.2 is stable โ but ensuring your custom modules and themes are compatible is crucial before upgrading your environment.
This guide walks you through using PHPCompatibility + PHP_CodeSniffer to audit your code for PHP 8.2 issues.
๐ ๏ธ Step 1: Install PHPCompatibility & PHPCS
Start by requiring the tools via Composer:
composer require --dev squizlabs/php_codesniffer
composer require --dev phpcompatibility/php-compatibility
This will install:
phpcs
: the linterPHPCompatibility
: a rule set to check PHP version compatibility
๐ Step 2: Scan Custom Magento Code
Run the following command to scan your custom modules and templates:
vendor/bin/phpcs \
--standard=PHPCompatibility \
--runtime-set testVersion 8.2 \
--extensions=php,phtml \
--ignore=*/vendor/*,*/pub/*,*/generated/* \
app/code/