Req #79695 [NEW]: Request nullability of mixed in php 8 be reconsidered
| From: | corey dot taylor dot fl at gmail dot com | Date: | Fri, 12 Jun 2020 06:32:00 +0000 |
| Subject: | Req #79695 [NEW]: Request nullability of mixed in php 8 be reconsidered | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227436@lists.php.net to get a copy of this message | ||
From: corey dot taylor dot fl at gmail dot com
Operating system:
PHP version: master-Git-2020-06-12 (snap)
Package: Compile Failure
Bug Type: Feature/Change Request
Bug description:Request nullability of mixed in php 8 be reconsidered
Description:
------------
We hope we can submit this for consideration as the RFC has just been
voted on and implemented.
According to the Nullability clause of
(https://wiki.php.net/rfc/mixed_type_v2#nullability),
?mixed will not
be a valid type as mixed will already include the type null.
You currently get this failure in master branch:
PHP Fatal error: Type mixed cannot be marked as nullable since mixed
already includes null in
/home/travis/build/cakephp/cakephp/src/basics.php on line 22
The clause says that a future RFC can allow the redundant types.
However, we think this makes code more difficult to write and harder to
correct later.
The other clauses state that untyped parameters will be evaluated as
mixed. Of course, untyped parameters should include null. However,
we think this can be changed similar to the wording in how untyped
returns are evaluated (mixed|void) to ?mixed or mixed|null.
Usually, then a type is mixed, it's because it supports many flavors
of input. Often these other inputs are documented via @param or
@psalm-param docblock entries. In most cases, we explicitly document
whether this includes a null value:
@param null|\Closure|\Project\Class
If null is automatically defined by mixed, then we lose the ability
to document that we expect a value to be set. Static analyzers will
complain that we don't include null when the type is mixed.
Static analyzers will have to create their own version of mixed for
untyped parameters support this kind of documentation. In most cases, we
will end up simply not type hinting to avoid the official mixed type.
Further, to the point of this need being discoverable and changed later,
it seems that requiring every mixed parameter and return type to be
changed to ?mixed to support even further static analyzer changes will
be very tedious. How will they be able to easily support this
transition?
Our request is that mixed not include null and untyped parameters be
treated as ?mixed. But, if nothing else, we would request supporting
redundant types ?mixed to help with type documentation and analysis.
Test script:
---------------
function test_null(?mixed $param): void
{
var_dump($param);
}
test_null(null);
--
Edit bug report at https://bugs.php.net/bug.php?id=79695&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79695&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79695&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79695&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79695&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79695&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79695&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79695&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79695&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79695&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79695&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79695&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79695&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79695&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79695&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79695&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79695&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79695&r=mysqlcfg