php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80283 Null constant in method signature did not allow nullable anymore
Submitted: 2020-10-26 08:40 UTC Modified: 2020-10-26 11:31 UTC
From: php-bugs at marcelthole dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.0RC2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php-bugs at marcelthole dot de
New email:
PHP Version: OS:

 

 [2020-10-26 08:40 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-26 08:43 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-10-26 08:59 UTC] 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 11:31 UTC] nikic@php.net
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).
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jul 07 01:04:05 2022 UTC