Re: Concept: Lightweight error channels

From: Date: Thu, 01 May 2025 02:18:48 +0000
Subject: Re: Concept: Lightweight error channels
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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).

Thread (34 messages)

« previous php.internals (#127259) next »