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

From: Date: Mon, 26 Oct 2020 08:40:40 +0000
Subject: Bug #80283 [NEW]: Null constant in method signature did not allow nullable anymore
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229920@lists.php.net to get a copy of this message
From:             php-bugs at marcelthole dot de
Operating system: 
PHP version:      8.0.0RC2
Package:          *General Issues
Bug Type:         Bug
Bug description:Null constant in method signature did not allow nullable anymore

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 bug report at https://bugs.php.net/bug.php?id=80283&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80283&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80283&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80283&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80283&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80283&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80283&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80283&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80283&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80283&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80283&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80283&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80283&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80283&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80283&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80283&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80283&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80283&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#229920) next »