Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Traditional throw statement function getUser(int $id): array { $user = db_query("SELECT * FROM users WHERE id = ?", [$id]); if (!$user) { throw new RuntimeException("User {$id} not found"); } return $user; } // PHP 8: throw as expression $age = $_GET["age"] ?? throw new InvalidArgumentException("Age required"); $user = findUser($id) ?? throw new NotFoundException("User not found"); $value = $condition ? "valid value" : throw new LogicException("Invalid condition");
Result
Open