Re: Union type casts
| From: | Claude Pache | Date: | Wed, 05 Oct 2022 18:16:05 +0000 |
| Subject: | Re: Union type casts | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118759@lists.php.net to get a copy of this message | ||
> Le 5 oct. 2022 à 19:53, Eugene Sidelnyk <zsidelnik@gmail.com> a écrit :
>
> I used to have an awkward feeling when it was necessary to convert the nullable integer into a
> nullable string. It would be kind of ternary operator anyway. Either
$b = (null !==
> $a) ? (string)$a : null; or $b = (string)$a ?:
> null;.
>
> A lot easier to read would it be if written this way: $b =
> (?string)$a;. The intentions are clear when doing explicit type-cast.
>
> Currently, I don't see any other situations when this feature may be useful
>
>
> Thank you
There has been some discussion and interest around nullable casting (which, contrarily to union type
casting, has only one possible and obvious semantics), see https://wiki.php.net/rfc/nullable-casting
<https://wiki.php.net/rfc/nullable-casting>
and the two discussion threads linked in the bottom of the page. However, the RFC seems to be
inactive for now,
—Claude