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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 26 19:01:29 2024 UTC