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

PHP 8.3 | Tokenizer/PHP: add support for typed OO constants #321

Merged
merged 1 commit into from
Feb 8, 2024

Commits on Feb 8, 2024

  1. PHP 8.3 | Tokenizer/PHP: add support for typed OO constants

    PHP 8.3 introduced typed OO constants, where the type is between the `const` keyword and the constant name.
    
    All type variations are supported, including nullable types, union types, intersection types, with the exception of `callable`, `void` and `never`.
    `self` and `static` types are only allowed in Enum constants.
    
    This PR adds support for typed OO constants in the Tokenizer layer of PHPCS.
    
    The following issues had to be fixed to support typed constants:
    1. Consistently tokenizing the constant _name_ as `T_STRING`, even if the name mirrors a reserved keyword, like `foreach` or a special keyword, like `self` or `true`.
    2. Tokenizing a `?` at the start of a constant type declaration as `T_NULLABLE`.
    3. Tokenizing a `|` and `&` operators within a constant type declaration as `T_TYPE_UNION` and `T_TYPE_INTERSECTION` respectively.
    
    Each and every part of the above has been covered by extensive tests.
    Includes additional tests safeguarding that the `array` keyword when used in a type declaration for a constant is tokenized as `T_STRING`.
    
    Ref: https://wiki.php.net/rfc/typed_class_constants
    jrfnl committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    53dd20c View commit details
    Browse the repository at this point in the history