Req #78640 [Opn->Wfx]: Add method allowsNull to ReflectionProperty

[email protected] Mon, 07 Oct 2019 12:55:20 +0000
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=78640&edit=1

 ID:                 78640
 Updated by:         [email protected]
 Reported by:        alan at aondra dot com
 Summary:            Add method allowsNull to ReflectionProperty
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            PHP Language Specification
 PHP Version:        7.4.0RC3
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2019-10-07 12:35:15] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78640&edit=1