Conversation
> **Never type** > > A new`return only type `never` has been added. This indicates that a function either `exit()`, throws an exception, or doesn't terminate. Includes unit tests. Refs: * https://wiki.php.net/rfc/noreturn_type * https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.never-type * php/php-src#6761 * php/php-src@6cd0b48
The `void`, `mixed` and the new `never` types are "stand-alone" types, i.e types which are not allowed to be combined with other types, so they cannot be part of a type union, nor can they be nullable. This is a cross-version compatibility issue as the name _could_ have been used, prior to the introduction of the type, as a class/interface name and could have been nullable or part of a union as the class/interface name. In the `NewReturnTypeDeclarations` sniff, this was so far only addressed by detecting the use of the nullable operator in combination with the `mixed` type. That particular check has now been refactored to be based on a list of types in the `$standAloneTypes` property and to check for both the nullability operator, as well as the use of the type in a type union. This includes a minor BC-break in that the `PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.NullableMixed` error code has now been changed to `PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.NonStandaloneMixed` . Includes unit tests and minor adjustments to the existing unit tests to accommodate.
wimg
approved these changes
Jan 3, 2023
47 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PHP 8.1 | NewReturnTypeDeclarations: handle new never return type
Includes unit tests.
Refs:
NewReturnTypeDeclarations: new check for non-standalone standalone types
The
void,mixedand the newnevertypes are "stand-alone" types, i.e types which are not allowed to be combined with other types, so they cannot be part of a type union, nor can they be nullable.This is a cross-version compatibility issue as the name could have been used, prior to the introduction of the type, as a class/interface name and could have been nullable or part of a union as the class/interface name.
In the
NewReturnTypeDeclarationssniff, this was so far only addressed by detecting the use of the nullable operator in combination with themixedtype.That particular check has now been refactored to be based on a list of types in the
$standAloneTypesproperty and to check for both the nullability operator, as well as the use of the type in a type union.This includes a minor BC-break in that the
PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.NullableMixederror code has now been changed toPHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.NonStandaloneMixed.Includes unit tests and minor adjustments to the existing unit tests to accommodate.