Re: [RFC] Nullable Return Type Declaration

From: Date: Mon, 18 Apr 2016 03:56:39 +0000
Subject: Re: [RFC] Nullable Return Type Declaration
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-92393@lists.php.net to get a copy of this message
On 04/17/2016 02:19 AM, Fleshgrinder wrote:
Everything always has pros and cons and I do not think that there is one answer to all of these questions. Different languages handle this problem differently. PHP has NULL and we should keep it this way. To minimize bugs resulting from unchecked NULL usage a compiler feature could be implemented that warns a developer in such cases. We already have it for uncatched exceptions (although IDEs are currently not telling one about that; Eclipse does in Java though).
Rather than debate the relative merits of Null as a concept, since I think all agree removing Null from the language is not even a thing, what do you think of my recommendation to NOT have the ? shorthand for "or null" on types, but keep the |null for union types? That is, if you want to return Foo or null, you have to use the long-hand version: function foo($a) : Foo|null That 1) Allows for explicit or-null behavior. 2) Doesn't make it quite so easy, which hopefully discourages (but does not prohibit) its usage. 3) Neatly avoids the ?Foo / Foo? question entirely. I think that's a win-win arrangement. --Larry Garfield

« previous php.internals (#92393) next »