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:49As 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
mentioned this pull request
40 tasks
jrfnl
changed the title
Php 8.0/account for new mixed type
PHP 8.0: account for new mixed type
jrfnl
changed the title
PHP 8.0: account for new mixed type
PHP 8.0: account for new mixed param/return/property type
wimg approved these changes Aug 24, 2020
wimg approved these changes Aug 24, 2020
wimg
deleted the
php-8.0/account-for-new-mixed-type
branch
RobjS
mentioned this pull request
1 task
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