Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aadmathijssen opened this issue Oct 9, 2023 · 0 comments

Comments

@aadmathijssen
Copy link
Collaborator

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 the development version currently contains false positives and false negatives.

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

No branches or pull requests

1 participant