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

Enum member names cannot be keywords #4813

Closed
ricardoboss opened this issue Nov 4, 2021 · 3 comments
Closed

Enum member names cannot be keywords #4813

ricardoboss opened this issue Nov 4, 2021 · 3 comments
Labels
status/waiting-for-feedback Waiting for feedback from original reporter type/bug Something is broken

Comments

@ricardoboss
Copy link

Q A
PHPUnit version 9.5.10
PHP version 8.1.0RC6-dev
Installation Method Composer

Summary

I am trying out the new PHP 8.1 enums and stumbled upon an inconsistency regarding enum member names. As it seems, neither PhpUnit or 3v4l allow PHP keywords as enum member names, whereas they are allowed as class constants. Since enums and cases are mostly handled like classes and constants, I think there is an inconsistency.

I already reported it at PhpStorm, because I thought they where to blame (their editor didn't warn me about using a keyword as a member name). There I learned, that this seems to be the correct way to handle this. YouTrack issue: https://youtrack.jetbrains.com/issue/WI-63788

Current behavior

The current behaviour spits out this error when using Continue as an enum member name during testing:

Cannot parse ResponseCode.php: Syntax error, unexpected T_CONTINUE, expecting T_STRING on line 7

How to reproduce

Write a test covering this piece of code and test it: https://3v4l.org/K8ksR#v8.1rc3

Expected behavior

No parsing errors, since the PHP interpreter itself also doesn't warn about this.

@ricardoboss ricardoboss added the type/bug Something is broken label Nov 4, 2021
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Nov 5, 2021
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Nov 5, 2021

@nikic Could this be PHP-Parser related? Because yesterday's release lists

Support reserved keywords as enum cases

as a change.

@ricardoboss
Copy link
Author

I actually think this was related to nikic/PHP-Parser#807, since I cannot reproduce it now. I tried using this source code: https://github.com/ricardoboss/phpunit-enum-keyword-parse-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/waiting-for-feedback Waiting for feedback from original reporter type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants