Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 24, 2020

As of PHP 8.0, mixed can 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 mixed type 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 mixed being a soft reserved keyword -, prior to PHP 8, a class could be named mixed, so a ?Mixed type 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 mixed type declarations

PHP 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

jrfnl added 3 commits August 24, 2020 01:49
As of PHP 8.0, `mixed` can be used as a parameter type for function declarations.

The RFC explicitly does not allow for the `mixed` type 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 `mixed` being a soft reserved keyword -, prior to PHP 8, a class _could_ be named `mixed`, so a `?Mixed` type 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:
* https://wiki.php.net/rfc/mixed_type_v2
* php/php-src#5313
* php/php-src@aec4c0f

Includes unit tests.
As of PHP 8.0, `mixed` can be used as a return type for function declarations.

The RFC explicitly does not allow for the `mixed` type 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 `mixed` being a soft reserved keyword -, prior to PHP 8, a class _could_ be named `mixed`, so a `?Mixed` type 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:
* https://wiki.php.net/rfc/mixed_type_v2
* php/php-src#5313
* php/php-src@aec4c0f

Includes unit tests.
Includes removing the `testNoViolationsInFileOnValidVersion()` test as the sniff will now throw errors either way.
As of PHP 8.0, `mixed` can be used as a type for property declarations.

The RFC explicitly does not allow for the `mixed` type 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 `mixed` being a soft reserved keyword -, prior to PHP 8, a class _could_ be named `mixed`, so a `?Mixed` type 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:
* https://wiki.php.net/rfc/mixed_type_v2
* php/php-src#5313
* php/php-src@aec4c0f

Includes unit tests.
@jrfnl jrfnl added Type: enhancement PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 24, 2020
@jrfnl jrfnl added this to the 10.0.0 milestone Aug 24, 2020
@jrfnl jrfnl requested a review from wimg August 24, 2020 00:11
@jrfnl jrfnl changed the title Php 8.0/account for new mixed type PHP 8.0: account for new mixed type Aug 24, 2020
@jrfnl jrfnl changed the title PHP 8.0: account for new mixed type PHP 8.0: account for new mixed param/return/property type Aug 24, 2020
@wimg wimg merged commit d4c98e5 into develop Aug 24, 2020
@wimg wimg deleted the php-8.0/account-for-new-mixed-type branch August 24, 2020 20:41
@jrfnl jrfnl removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants