Bug #80948 [Opn->Nab]: Optional parameter can be null oven when type hint says no
| From: | nikic@php.net | Date: | Mon, 12 Apr 2021 08:45:45 +0000 |
| Subject: | Bug #80948 [Opn->Nab]: Optional parameter can be null oven when type hint says no | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233356@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80948&edit=1
ID: 80948
Updated by: nikic@php.net
Reported by: andre at webkr dot de
Summary: Optional parameter can be null oven when type hint
says no
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 8.0.3
Block user comment: N
Private report: N
New Comment:
For backwards-compatibility reasons, a null default value on a parameter type makes the type
nullable.
Previous Comments:
------------------------------------------------------------------------
[2021-04-12 08:25:56] andre at webkr dot de
Description:
------------
When a function parameter has a non-nullable type hint, it is still possible to give it a default of
null.
Test script:
---------------
function foo(string $foo = null) {
var_dump($foo);
}
foo();
Expected result:
----------------
Fatal error: Cannot use null as default value for parameter $foo of type string
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80948&edit=1