Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpcs --standard=PHPCompatibility not detecting anything from PHP 8.0+

Tags:

php

phpcs

I am running phpcs with the following command:

php -d memory_limit=-1 vendor/bin/phpcs -v -p . --standard=PHPCompatibility --extensions=php --colors --runtime-set testVersion 8.1

However, it is only finding deprecation and errors for PHP 7.4 and below. If I set testVersion to any PHP version of 7.4 or below, it works as expected. With the above command, it only finds compatibility issues for 7.4.

To test, I added a new deprecation and removed function from 8.1 and it does not detect them.

like image 358
Bill Johnson Avatar asked Sep 17 '26 21:09

Bill Johnson


1 Answers

I suspect this is because you're using a version of PHPCompatibility that does not yet know about PHP 8.x features. The current tagged release, as of this writing, is 9.3.5, which was released on Dec 27, 2019.

It appears that compatibility checks for PHP 8.0, 8.1, and 8.2 only exist in the develop branch, and so you will need to specify dev-develop in your composer.json to be able to run checks for those versions.

This should switch you to the dev-develop branch:

 composer require --dev phpcompatibility/php-compatibility dev-develop

I was in a similar situation (I have code I know is not supported in PHP 8.x, but was not being flagged) and switching to dev-develop allowed it to be detected properly while using the PHPCompatibility standard with phpcs.

like image 186
joel boonstra Avatar answered Sep 20 '26 13:09

joel boonstra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!