Hi!

2016-04-17 23:56 GMT-04:00 Larry Garfield <la...@garfieldtech.com>:

> 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
>
>
I can agree with that.

Language design wise, if you have no way to forecast how language features
independently proposed are going to interact then it's a good idea to have
a converging strategy. Fortunately, this seems to be happening almost
spontaneously towards union types representation, as in the "multiple
catch" RFC (https://wiki.php.net/rfc/multiple-catch) now in voting phase.

Even if we decide not to commit to a full union types implementation now,
the design process will be much easier in the future if we decide to use
Foo|null instead of Foo? or ?Foo and we will not end up with 2 or 3 ways
alternative to declare the same thing.

Cheers,
Márcio

Reply via email to