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: 2018-06-14 17:30 UTC
From: daverandom@php.net Assigned:
Status: Verified Package: Reflection related
PHP Version: 7.1 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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).
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 13:01:25 2019 UTC