On 2024-03-21 16:02, Robert Landers wrote:
$a as int|float

would be an int, float, or thrown exception.

$a as int|float|null

would be an int, float, or null.

Just a suggestion here which might be more palatable to Rowan's wish for consistency (which I can totally relate to):

We perhaps could make sure that as does not throw if used with `??`, or that `??` catches the type error and returns the right-hand expression instead:

So to do a nullable typecast you would do:

    $a as int|float ?? null

To me this reads way more intuitive what will happen, and achieves the same in an also very concise way.

The only catch I see is that it would also swallow errors about $a not being defined at all.

Best,
Jordi

--
Jordi Boggiano
@seldaek -https://seld.be

Reply via email to