Re: [RFC] Nullable and non-nullable cast operators

From: Date: Sat, 25 Oct 2025 07:54:01 +0000
Subject: Re: [RFC] Nullable and non-nullable cast operators
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-128960@lists.php.net to get a copy of this message

On Sat, Oct 25, 2025, at 09:40, Aleksander Machniak wrote:
> On 24.10.2025 09:07, Alexandre Daubois wrote:
> > Please find the details here:
> > https://wiki.php.net/rfc/nullable-not-nullable-cast-operator
> I see two issues here, and I'm not sure how I feel about them.
> 
> 1. The new operators not only change how NULL is handled, but also add 
> validation rules. So, their name should be changed, maybe "nullable 
> validating cast". I guess "strict" word would not work as they aren't 
> really strict.
> 
> 2. They are supposed to have behavior in line with function arguments, 
> but they don't react to strict_types.

The RFC says: "using *weak mode function parameter coercion* (stricter than traditional
casts)." (emphasis not mine) If it were to act like strict-mode arguments, it’d be more like
a type-check than a cast. The entire point of a cast is to "turn one type into another"
and strict mode doesn’t do that at all. Parameter coercion in non-strict mode (I hesitate to call
it "weak mode" because in some ways it’s stronger than strict mode) is a well-documented
behaviour, and if you’re used to working with it, this is a welcome addition, IMHO.

— Rob


Thread (18 messages)

« previous php.internals (#128960) next »