Bug #80283 [Nab]: Null constant in method signature did not allow nullable anymore

From: Date: Mon, 26 Oct 2020 11:31:38 +0000
Subject: Bug #80283 [Nab]: Null constant in method signature did not allow nullable anymore
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229926@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80283&edit=1 ID: 80283 Updated by: nikic@php.net Reported by: php-bugs at marcelthole dot de Summary: Null constant in method signature did not allow nullable anymore Status: Not a bug Type: Bug Package: *General Issues PHP Version: 8.0.0RC2 Block user comment: N Private report: N New Comment: Are you referring to deprecation messages? If so, no, there has been no deprecation message for this change. We might deprecate implicit argument nullability entirely in the future, but I don't believe this is a consensus for that (yet). Previous Comments: ------------------------------------------------------------------------ [2020-10-26 08:59:03] php at kriegt dot es Is that intentional behavior documented in one of the breaking changes messages? Not sure if I've ever seen anything regarding this behavior. ------------------------------------------------------------------------ [2020-10-26 08:43:37] nikic@php.net This is an intentional change, documented here: https://github.com/php/php-src/blob/0535872b7cd50be8b40ad06154b287749315eb27/UPGRADING#L97-L106 ------------------------------------------------------------------------ [2020-10-26 08:40:40] php-bugs at marcelthole dot de Description: ------------ In PHP < 8.0 it was possible to make an argument nullable without the question mark if the default value is null. This works fine if the variable is directly null, but not when the default value is an CONST with a null value Test script: --------------- <?php declare(strict_types=1); const ALLOW_ANY = null; var_dump(ALLOW_ANY); function foo(array $baz = ALLOW_ANY) { return true; } var_dump(foo(NULL)); Expected result: ---------------- NULL bool(true) Actual result: -------------- NULL Fatal error: Uncaught TypeError: foo(): Argument #1 ($baz) must be of type array, null given, called in /in/RLUo7 on line 14 and defined in /in/RLUo7:9 Stack trace: #0 /in/RLUo7(14): foo(NULL) #1 {main} thrown in /in/RLUo7 on line 9 Process exited with code 255. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80283&edit=1

« previous php.bugs (#229926) next »