Re: Proposal: AS assertions
| From: | Rowan Tommins [IMSoP] | Date: | Wed, 20 Mar 2024 19:30:18 +0000 |
| Subject: | Re: Proposal: AS assertions | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122701@lists.php.net to get a copy of this message | ||
On 20 March 2024 12:51:15 GMT, Robert Landers <landers.robert@gmail.com> wrote:
>Oh and there isn't any difference between:
>
>$x as ?Type
>
>or
>
>$x as Type|null
I'm not sure if I've misunderstood your example, or you've misunderstood mine.
I'm saying that this should be an error, because the value is neither an instance of Foo nor
null:
$a = 42;
$b = $a as Foo|null;
Your earlier example implies that would make $b equal null, which feels wrong to me, because it
means it wouldn't match this:
$a = 42;
$b = $a as Foo|Bar;
If we want a short-hand for "set to null on error" that should be separate from the syntax
for a nullable type.
Regards,
Rowan Tommins
[IMSoP]