# [VOTE] nullsafe operator RFC

- Thread: https://externals.io/message/111061
- Original archive: https://news-web.php.net/php.internals/111061
- Started by Ilija Tovilo on 2020-07-17T09:04:41+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #111061 — Ilija Tovilo — 2020-07-17T09:04:41+00:00

URL: https://externals.io/message/111061#111061

Hi internals

I started the vote on the nullsafe operator RFC.
https://wiki.php.net/rfc/nullsafe_operator

The vote closes on 2020-07-31.

Ilija

---

## #111062 — Dan Ackroyd — 2020-07-17T09:15:48+00:00

URL: https://externals.io/message/111061#111062 · In reply to: #111061

>
> Hi internals
>
> I started the vote on the nullsafe operator RFC.
> https://wiki.php.net/rfc/nullsafe_operator
>
> The vote closes on 2020-07-31.

I'm voting yes.

From the discussions I've seen, there are two overlapping reasons
people have said for why they don't like this proposal.

"checking that the value is null should be a red flag that something
is wrong with the data model."

Even if there is something wrong with the data model, programmers are
often in a position where they can't change the data model.

That can be because it's part of an api/library that's provided by a
3rd party, or is part of a legacy code base that can't be refactored
right now.

PHP exists to be useful. Adding a small feature that makes it easier
to work with some data models is a useful thing to do.

But also, sometimes the data just is null.

Whether you use a null type, a type union, Option<T>, a Nothing-type
or whatever, it's got to be handled somewhere. This RFC provides a way
of handling it in a way that is very easy to write and read, imo.

I realise that some people would prefer to not use this syntax in
their own code, which is fine. But as it makes coding easier for other
people, I hope people would only vote no for a stronger reason than
they would personally prefer not to use it.

cheers
Dan
Ack

---

## #111274 — Ilija Tovilo — 2020-07-31T08:58:24+00:00

URL: https://externals.io/message/111061#111274 · In reply to: #111061

Hi internals

> I started the vote on the nullsafe operator RFC.
> https://wiki.php.net/rfc/nullsafe_operator

I'm happy to announce that the RFC was accepted with 56 votes in favor
and 2 votes against. Thanks to everybody who participated!

Ilija

---

## #111379 — Nikita Popov — 2020-08-08T20:10:13+00:00

URL: https://externals.io/message/111061#111379 · In reply to: #111274

On Fri, Jul 31, 2020 at 10:59 AM Ilija Tovilo <tovilo.ilija@gmail.com>
wrote:

> Hi internals
>
> > […]
>
> I'm happy to announce that the RFC was accepted with 56 votes in favor
> and 2 votes against. Thanks to everybody who participated!
>
> Ilija
>

I just noticed that while we support "$a->b", we do not support "$a?->b"
(the quotes are relevant -- I'm talking about interpolated strings here).
That is, in the latter case the "?->b" is just treated like a string part,
not like a property access.

I don't think the behavior for this case has been discussed and I'm not
sure what the intended behavior here is.

Nikita

---

## #111380 — Ilija Tovilo — 2020-08-08T20:34:23+00:00

URL: https://externals.io/message/111061#111380 · In reply to: #111379

Hi Nikita

> > […]
>
> I just noticed that while we support "$a->b", we do not support "$a?->b" (the quotes are relevant -- I'm talking about interpolated strings here). That is, in the latter case the "?->b" is just treated like a string part, not like a property access.
>
> I don't think the behavior for this case has been discussed and I'm not sure what the intended behavior here is.

I missed that one. There's a test for var_dump("{$null?->foo}"); but
not one without the braces. I would classify this as a bug and expect
this to behave the same as -> (but not erroring on null obviously).
Worth noting that chaining won't work as it doesn't work for ->
either.

Sara/Gabriel, What do you think? Should we fix this? I'm assuming this
will only require a change in the grammar but I haven't checked yet.

Ilija

---

## #111382 — Ilija Tovilo — 2020-08-08T20:42:36+00:00

URL: https://externals.io/message/111061#111382 · In reply to: #111380

Hi again

> > […]
>
> I missed that one. There's a test for var_dump("{$null?->foo}"); but
> not one without the braces. I would classify this as a bug and expect
> this to behave the same as -> (but not erroring on null obviously).
> Worth noting that chaining won't work as it doesn't work for ->
> either.
>
> Sara/Gabriel, What do you think? Should we fix this? I'm assuming this
> will only require a change in the grammar but I haven't checked yet.

Just as I sent this I realized this is technically a breaking change,
probably a small one but still worth mentioning. I'm now also not
totally sure if we should change it at this point. Let me know what
you think.

Ilija

---

## #111384 — Sara Golemon — 2020-08-08T22:24:29+00:00

URL: https://externals.io/message/111061#111384 · In reply to: #111382

> > […]
> "$a?->b" (the quotes are relevant -- I'm talking about interpolated strings
> here). That is, in the latter case the "?->b" is just treated like a string
> part, not like a property access.
> > […]
> not sure what the intended behavior here is.
> > […]
>
> Just as I sent this I realized this is technically a breaking change,
> probably a small one but still worth mentioning. I'm now also not
> totally sure if we should change it at this point. Let me know what
> you think.
>
>
Hah! And just as I sent my previous message, I noticed you started THIS
thread before asking me about it elsewhere.  Circles....


Anyway, IMO this comes under bugfix.  By all means fix it up. :D

-Sara

---

## #111385 — tyson andre — 2020-08-09T00:03:02+00:00

URL: https://externals.io/message/111061#111385 · In reply to: #111382

Hi Ilija Tovilo,

> > […]
>
> Just as I sent this I realized this is technically a breaking change,
> probably a small one but still worth mentioning. I'm now also not
> totally sure if we should change it at this point. Let me know what
> you think.

To me, that sounds like a reasonable bugfix for 8.0 and something most applications wouldn't be using before php 8.0.
I'd missed whether the RFC mentioned it or not.

- Tyson
