php.net |  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: daverandom@php.net Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.1 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daverandom@php.net
New email:
PHP Version: OS:

 

 [2018-06-14 16:39 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-14 16:46 UTC] daverandom@php.net
-PHP Version: Irrelevant +PHP Version: >=5.5
 [2018-06-14 17:30 UTC] cmb@php.net
-Status: Open +Status: Verified -PHP Version: >=5.5 +PHP Version: 7.1
 [2018-06-14 17:30 UTC] 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).
 [2020-02-28 15:18 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-02-28 15:18 UTC] nikic@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC