|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76478 ReflectionParameter#allowsNull() returns false for indirect nullable decls
Submitted: 2018-06-14 16:39 UTC Modified: 2020-02-28 15:18 UTC
From: Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.1 OS: Any
Private report: No CVE-ID: None
 [2018-06-14 16:39 UTC]
ReflectionParameter#allowsNull() return false for parameters where the nullability is inferred by a constant default value, where the constant has a value of NULL.

Test script:

const DEFAULT_VALUE = null;

function foo(\stdClass $arg = DEFAULT_VALUE)

var_dump((new ReflectionFunction('foo'))->getParameters()[0]->allowsNull());

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-14 16:46 UTC]
-PHP Version: Irrelevant +PHP Version: >=5.5
 [2018-06-14 17:30 UTC]
-Status: Open +Status: Verified -PHP Version: >=5.5 +PHP Version: 7.1
 [2018-06-14 17:30 UTC]
It's interesting that ::getDefaultValue() returns NULL in this
case (<>), and that PHP < 5.6.4 didn't even
allow this function definition (likely due to bug #68446).
 [2020-02-28 15:18 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-02-28 15:18 UTC]
This has been "fixed" in PHP 8 by the removal of Schrödinger's nullability. The parameter is either nullable, or it is not. Your example will no longer be considered as nullable.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Sep 29 20:03:56 2022 UTC