Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

phpcompatibility/php-compatibility dependency is not compatible with PHP 8 #43

Open
aadmathijssen opened this issue Feb 7, 2023 · 0 comments

Comments

@aadmathijssen
Copy link
Member

This package depends on version "^9.3" of the phpcompatibility/php-compatibility dependency.

This includes the latest stable version 9.3.5, which is now more than 3 years old. As a result, PHP 8 is not fully supported. This introduces lots of missed cases, but can also introduces false positives.

For example, consider this backed enum code:

<?php

enum Foo: string
{
    case Bar = 'bar';

    public function getValue(): string
    {
        return $this->value;
    }
}

This generates an error regarding the use of $this:

$ vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.1 file.php

FILE: /path/to/file.php
-----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------
 9 | ERROR | "$this" can no longer be used in a plain function or method since PHP 7.1.
-----------------------------------------------------------------------------------------------------

A temporary workaround is to make use of the latest dev-develop version of this dependency, which has much better support for PHP 8.
To include this in a project that uses the ISAAC PHP_CodeSniffer Standard, you can upgrade the dependency

$ composer require --dev --with-all-dependencies "phpcompatibility/php-compatibility:dev-develop as 9.3.5"

However, I am hesitant to create a PR to update phpcompatibility/php-compatibility to dev-develop, as I only want to depend on stable package version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant