|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80948 Optional parameter can be null oven when type hint says no
Submitted: 2021-04-12 08:25 UTC Modified: 2021-04-12 08:45 UTC
From: andre at webkr dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.3 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.
Block user comment
Status: Assign to:
Bug Type:
From: andre at webkr dot de
New email:
PHP Version: OS:


 [2021-04-12 08:25 UTC] andre at webkr dot de
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) {

Expected result:
Fatal error: Cannot use null as default value for parameter $foo of type string

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-12 08:45 UTC]
-Status: Open +Status: Not a bug
 [2021-04-12 08:45 UTC]
For backwards-compatibility reasons, a null default value on a parameter type makes the type nullable.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 07:01:49 2024 UTC