PHP 8.0: account for new mixed param/return/property type by jrfnl · Pull Request #1217 · PHPCompatibility/PHPCompatibility

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 mentioned this pull request

Aug 24, 2020

40 tasks

@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 approved these changes Aug 24, 2020

wimg

wimg approved these changes Aug 24, 2020

@wimg wimg deleted the php-8.0/account-for-new-mixed-type branch

August 24, 2020 20:41

@RobjS RobjS mentioned this pull request

Sep 28, 2020

1 task