Re: [RFC] Nullable Casting
| From: | Nikita Popov | Date: | Wed, 10 Apr 2019 10:52:22 +0000 |
| Subject: | Re: [RFC] Nullable Casting | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105202@lists.php.net to get a copy of this message | ||
On Sat, Apr 6, 2019 at 9:53 AM Guilliam Xavier <guilliam.xavier@gmail.com>
wrote:
> Hello internals,
>
> David and I would like to open the discussion on our joint RFC:
>
> https://wiki.php.net/rfc/nullable-casting
>
> Mainly, it would enable to use e.g.
(?int)$x besides
> (int)$x.
>
> We are looking forward to your feedback and, if possible, help to fill
> in the "RFC Impact" subsections (hopefully "None" to all) as well as a
> review of the proposed implementation:
>
> https://github.com/php/php-src/pull/3764
I'm a bit concerned that there are two possible semantics for what (?int)
does:
1. What I would intuitively expect: A fallible integer cast. I.e. try to
cast to integer and if not possible return null. So (?int) "foobar" becomes
null rather than 0.
2. What this RFC proposes: A normal integer cast that leaves null alone.
Both behaviors make sense to me generally ... and if there are two ways to
interpret a piece of syntax, I'd say the syntax is not explicit enough.
Nikita