Re: [RFC] Alternative typehinting syntax for accessors
| From: | Steve Clay | Date: | Tue, 08 Jan 2013 18:03:59 +0000 |
| Subject: | Re: [RFC] Alternative typehinting syntax for accessors | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64695@lists.php.net to get a copy of this message | ||
On 1/8/13 2:56 AM, Christian Stoller wrote:
But the way 'nullable' properties are defined is not very intuitive and unclean, in my opinion. Stas has already mentioned that.
public DateTime $date = NULL; // this looks like the property is initialized with null, but it does not show that the property is 'nullable'
Much agreed. After instantiation, these shouldn't behave differently:
public $foo = null;public Foo $foo = null; Sure, method signatures have special behavior based on a default value, but IMO: 1. those semantics aren't entirely intuitive to begin with 2. property initializers aren't method sigs 3. the semantics would apply only to some properties
I like that it's an established practice of doing exactly what we're trying to do. Could we not just make it obvious?: public Foo|null $foo; Steve Clay -- http://www.mrclay.org/public DateTime? $date;In C# the question mark after a type is a short hand for a generic Nullable type.