Bug #76478 [Ver->Csd]: ReflectionParameter#allowsNull() returns false for indirect nullable decls
| From: | nikic@php.net | Date: | Fri, 28 Feb 2020 15:18:07 +0000 |
| Subject: | Bug #76478 [Ver->Csd]: ReflectionParameter#allowsNull() returns false for indirect nullable decls | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225793@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76478&edit=1
ID: 76478
Updated by: nikic@php.net
Reported by: daverandom@php.net
Summary: ReflectionParameter#allowsNull() returns false for
indirect nullable decls
-Status: Verified
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: Any
PHP Version: 7.1
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-06-14 17:30:42] cmb@php.net
It's interesting that ::getDefaultValue() returns NULL in this
case (<https://3v4l.org/R8WYD>), and that PHP < 5.6.4
didn't even
allow this function definition (likely due to bug #68446).
------------------------------------------------------------------------
[2018-06-14 16:39:10] daverandom@php.net
Description:
------------
ReflectionParameter#allowsNull() return false for parameters where the nullability is inferred by a
constant default value, where the constant has a value of NULL.
https://3v4l.org/mUePZ
Test script:
---------------
<?php
const DEFAULT_VALUE = null;
function foo(\stdClass $arg = DEFAULT_VALUE)
{
var_dump($arg);
}
var_dump((new ReflectionFunction('foo'))->getParameters()[0]->allowsNull());
foo(null);
Expected result:
----------------
bool(true)
NULL
Actual result:
--------------
bool(false)
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76478&edit=1