Skip to main content

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 linter
  • PHPCompatibility: 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/

 

Tags