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

Infection crashes when using PHP 8.1 reserved keywords as enum cases #1656

Closed
ABSAhmad opened this issue Jan 27, 2022 · 3 comments
Closed

Infection crashes when using PHP 8.1 reserved keywords as enum cases #1656

ABSAhmad opened this issue Jan 27, 2022 · 3 comments
Labels

Comments

@ABSAhmad
Copy link

Question Answer
Infection version 0.26.3
Test Framework version PHPUnit 9.5.11
PHP version 8.1.1
Platform php:8.1-fpm Dockerimage
Github Repo -

When using a PHP 8.1 enum with a reserved keyword e.g. empty as a case, infection will crash.

Error message:

In UnparsableFile.php line 13: Could not parse the file "[removed]/DepotState.php". Check if it is a valid PHP file                                                                                   

In ParserAbstract.php line 161: Syntax error, unexpected T_EMPTY, expecting T_STRING on line 9  

Enum example:

enum DepotState : string
{
    case empty = 'empty';
    
    public static function fromLabel(string $stateCode): ?self
    {
        return match ($stateCode) {
            '00' => self::empty,
            default => null
        };
    }
}

As far as I can tell, this is an issue with the nikic/PHP-Parser package but has been fixed in version 4.13.1.

See: nikic/PHP-Parser#807

Can I just create a PR updating the PHP parser package or is there something I should pay attention to/take care of?

@maks-rafalko
Copy link
Member

Am I right that you are using PHAR?

Released https://github.com/infection/infection/releases/tag/0.26.4

@ABSAhmad
Copy link
Author

Yes, sorry for not including that information.

Many thanks for the quick fix and release. This solved the issue :)

@maks-rafalko
Copy link
Member

Thank you @ABSAhmad for sponsoring us!

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

No branches or pull requests

3 participants