PHP 8.0: account for new mixed param/return/property type #1217
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.
As of PHP 8.0,
mixedcan be used as a parameter type for function declarations, a return type for function declarations and as a property type.The RFC explicitly does not allow for the
mixedtype to be combined with the nullability indicator.While in itself, that is not a cross-version compatibility issue, I have made a very conscious choice to add a check for this anyway as - while discouraged with
mixedbeing a soft reserved keyword -, prior to PHP 8, a class could be namedmixed, so a?Mixedtype hint referring to such a class could exist in code and would be a cross-version compatibility issue as since PHP 8 that will throw a "Fatal error: Mixed types cannot be nullable".Refs:
Includes unit tests.
Related to #809
PHP 8.0: NewParamTypeDeclarations: allow for
mixedtype declarationsPHP 8.0: NewReturnTypeDeclarations: allow for "mixed" return type
Includes removing the
testNoViolationsInFileOnValidVersion()test as the sniff will now throw errors either way.PHP 8.0: NewTypedProperties: allow for "mixed" type