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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to