On Wed, Apr 30, 2025, at 9:18 PM, Morgan wrote:
> On 2025-04-28 06:06, Larry Garfield wrote:
>> Which is why I think we do want some kind of syntax similar to Rust's ?, so 
>> the above could be shortened back to this:
>> 
>> function doStuff($id): string raises UserErr {
>>    $user = $repo->getUser($id) reraise;
>>    // We have a good user.
>> }
>
> One thing about Rust's ?, compared with an additional "reraise" keyword 
> thingy, is that the former is inline with the rest of the expression 
> while the latter forces a distinct statement for each possible failure 
> point. The "happy path" no longer looks quite so happy.
>
> In other words, Rust's approach looks syntactically a lot more like 
> PHP's "?->" nullsafe access, which can be looked on as addressing the 
> specific case of "returning null to indicate failure" approach to error 
> handling (in the even more specific case where the happy path would have 
> returned an object).

One of the related ideas I had (but omitted from the initial post for brevity) 
was to require error objects to implement a new marker interface, which would 
cause the object to behave like null as far as nullsafe operators were 
concerned.  Or possibly some other set of operators, I'm not sure.  But some 
way to allow error objects to behave differently in a convenient way.  (This is 
the sort of thing I've not worked out yet because I don't know if it's worth 
it.)

--Larry Garfield

Reply via email to