PHP 8.3 | Tokenizer/PHP: add support for typed OO constants #321
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
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
andnever
.self
andstatic
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:
T_STRING
, even if the name mirrors a reserved keyword, likeforeach
or a special keyword, likeself
ortrue
.?
at the start of a constant type declaration asT_NULLABLE
.|
and&
operators within a constant type declaration asT_TYPE_UNION
andT_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 asT_STRING
.Ref: https://wiki.php.net/rfc/typed_class_constants
Suggested changelog entry
Related issues/external references
Related to #106
Types of changes