php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78640 Add method allowsNull to ReflectionProperty
Submitted: 2019-10-07 12:35 UTC Modified: 2019-10-07 14:13 UTC
From: alan at aondra dot com Assigned:
Status: Wont fix Package: Reflection related
PHP Version: 7.4.0RC3 OS:
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: alan at aondra dot com
New email:
PHP Version: OS:

 

 [2019-10-07 12:35 UTC] alan at aondra dot com
Description:
------------
With the introduction of typed class properties, there is also the nullable flag represented as a question mark, for example:

    class Foo
    {
        public ?string $bar;
    }

In keeping with the naming convention in ReflectionParameter and ReflectionType, the request is to also include a method with this name in the ReflectionProperty.

Test script:
---------------
class Foo
{
    public ?string $bar;
    public string $baz;
}

$barMeta = new ReflectionProperty(Foo::class, 'bar');
$bazMeta = new ReflectionProperty(Foo::class, 'baz');

var_dump( $barMeta->allowsNull() );
var_dump( $bazMeta->allowsNull() );


Expected result:
----------------
true
false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-07 12:55 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2019-10-07 12:55 UTC] nikic@php.net
Nullability if part of the type, so it needs to be accessed through $prop->getType()->allowsNull(). We'll not mirror the legacy ReflectionParameter methods here.
 [2019-10-07 13:17 UTC] alan at aondra dot com
Alright, thank you for documenting that.
 [2019-10-07 14:13 UTC] requinix@php.net
-Package: PHP Language Specification +Package: Reflection related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC