Re: [RFC] Nullable Types

From: Date: Thu, 14 Apr 2016 10:09:52 +0000
Subject: Re: [RFC] Nullable Types
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-92292@lists.php.net to get a copy of this message
On 14/04/16 10:59, Davey Shafik wrote:
On Thu, Apr 14, 2016 at 2:00 AM, Derick Rethans <derick@php.net> wrote:
On Wed, 13 Apr 2016, Levi Morrison wrote:
As alluded to in an earlier email today[1] I am now moving the Nullable Types RFC[2] to the discussion phase. In a nutshell this RFC proposes syntax for declaring a type to alternatively be null. There is a decision that needs to be made: does the question mark go before or after the type name?
     function (?Foo $foo);
     function (Foo? $foo);
There are precedents in several languages for each position. Some relevant issues to where the question mark goes are noted in the RFC[3].
Please put it where HHVM puts it: in front of it. Other languages are less of an issue than a syntax that's already used in a somewhat PHP language. As to the rest of the RFC: LGTM!
I much prefer the "Nullable Foo" (?Foo) to "Foo or Null" (Foo?). I find it easier to read. However, I am not a fan of introducing both this and the "Null" type for union types — this should be the only way to create nullable types. We already have too many things that are possible in more than one way. As it sits, this is purely syntactic sugar (when taken in tandem with union types) and [if] we agree that it is good, then let us just forgo the other syntax entirely. I'll add a little about that on the appropriate thread. - Davey Also agree, the "nullable foo" reads better and has the advantage of compatibility
with HHVM. The easier we make it for people to switch interpreters (and develop software which works on both interpreters) the better for PHP as a whole. Also agree that we don't need null union types if we have nullable types. - Matt

« previous php.internals (#92292) next »