Req #78640 [Com]: Add method allowsNull to ReflectionProperty
| From: | alan at aondra dot com | Date: | Mon, 07 Oct 2019 13:17:13 +0000 |
| Subject: | Req #78640 [Com]: Add method allowsNull to ReflectionProperty | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-1462@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78640&edit=1
ID: 78640
Comment by: alan at aondra dot com
Reported by: alan at aondra dot com
Summary: Add method allowsNull to ReflectionProperty
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:
Alright, thank you for documenting that.
Previous Comments:
------------------------------------------------------------------------
[2019-10-07 12:55:20] 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 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