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).