Have you used Rust (or Go, or anything else) and just felt relieved by how they treat errors?
Alright, I need to vent. I've reflecting about engineering recently I swear, exception handling in PHP feels like duct taping over a leaking pipe. Like, why is everything so optional? You can throw exceptions, sure, but half the time you're just praying that some function doesn't silently fail or spit out false without context. Meanwhile, I’ve been playing with Rust and Go lately and bro... it’s like, it feels safer (?). Every error is explicit. Either it worked (Ok) or it didn’t (Err), and you have to handle it. You don’t get to ignore it and pretend everything’s fine. The compiler literally says: "Nope, go back and deal with it." But I feel that do that in PHP would be an Anti-Pattern but at the same time would be safer to work with this type of "Result Objects". With Exceptions function getUser(int $id): array { // Simulate DB access or something that might throw if ($id $id, 'name' => 'Daniel']; } try { $user = getUser(0); // ⚠️ This will throw echo "User name: " . $user['name']; } catch (InvalidArgumentException $e) { echo "Caught exception: " . $e->getMessage(); } catch (Exception $e) { echo "Something went wrong: " . $e->getMessage(); } With a Result Class class Result { private function __construct( public bool $isOk, public mixed $value = null, public mixed $error = null ) {} public static function ok(mixed $value): self { return new self(true, $value); } public static function err(mixed $error): self { return new self(false, null, $error); } public function isOk(): bool { return $this->isOk; } public function unwrap() { if (!$this->isOk) { throw new RuntimeException("Tried to unwrap an Err: {$this->error}"); } return $this->value; } public function unwrapOr(mixed $fallback): mixed { return $this->isOk ? $this->value : $fallback; } public function getError(): mixed { return $this->error; } } // -------------- function getUser(int $id): Result { if ($id $id, 'name' => 'Daniel']); } $result = getUser(0); if ($result->isOk()) { $user = $result->unwrap(); echo "User name: " . $user['name']; } else { echo "Error: " . $result->getError(); } I know that the "lack" of generics (annotations solve this partially) makes it harder to accomplish, but I mean, this would improve the whole ecosystem IMHO. Also I just started to think about that because recently Microsoft started the revamp/reload/renew of typescript in go and I was wondering: what would be if PHP got a new engine (since Zend Engine is a total mess) with a couple of new features? Would be amazing.

Alright, I need to vent. I've reflecting about engineering recently I swear, exception handling in PHP feels like duct taping over a leaking pipe.
Like, why is everything so optional? You can throw exceptions, sure, but half the time you're just praying that some function doesn't silently fail or spit out false without context.
Meanwhile, I’ve been playing with Rust and Go lately and bro... it’s like, it feels safer (?). Every error is explicit. Either it worked (Ok) or it didn’t (Err), and you have to handle it. You don’t get to ignore it and pretend everything’s fine. The compiler literally says: "Nope, go back and deal with it."
But I feel that do that in PHP would be an Anti-Pattern but at the same time would be safer to work with this type of "Result Objects".
With Exceptions
function getUser(int $id): array {
// Simulate DB access or something that might throw
if ($id <= 0) {
throw new InvalidArgumentException("Invalid user ID");
}
return ['id' => $id, 'name' => 'Daniel'];
}
try {
$user = getUser(0); // ⚠️ This will throw
echo "User name: " . $user['name'];
} catch (InvalidArgumentException $e) {
echo "Caught exception: " . $e->getMessage();
} catch (Exception $e) {
echo "Something went wrong: " . $e->getMessage();
}
With a Result Class
class Result {
private function __construct(
public bool $isOk,
public mixed $value = null,
public mixed $error = null
) {}
public static function ok(mixed $value): self {
return new self(true, $value);
}
public static function err(mixed $error): self {
return new self(false, null, $error);
}
public function isOk(): bool {
return $this->isOk;
}
public function unwrap() {
if (!$this->isOk) {
throw new RuntimeException("Tried to unwrap an Err: {$this->error}");
}
return $this->value;
}
public function unwrapOr(mixed $fallback): mixed {
return $this->isOk ? $this->value : $fallback;
}
public function getError(): mixed {
return $this->error;
}
}
// --------------
function getUser(int $id): Result {
if ($id <= 0) {
return Result::err("Invalid user ID");
}
return Result::ok(['id' => $id, 'name' => 'Daniel']);
}
$result = getUser(0);
if ($result->isOk()) {
$user = $result->unwrap();
echo "User name: " . $user['name'];
} else {
echo "Error: " . $result->getError();
}
I know that the "lack" of generics (annotations solve this partially) makes it harder to accomplish, but I mean, this would improve the whole ecosystem IMHO.
Also I just started to think about that because recently Microsoft started the revamp/reload/renew of typescript in go and I was wondering: what would be if PHP got a new engine (since Zend Engine is a total mess) with a couple of new features? Would be amazing.