PHP Non-capturing Catches

Description

Since [PHP 8.0](PHP 8.0), exceptions are allowed without capturing them into variables[fn:rfc].

Syntax

Pre PHP8

try {
changeImportantData();
} catch (PermissionException $ex) {
echo “You don’t have permission to do this”;
}

Post PHP8

try {
changeImportantData();
} catch (PermissionException) { // The intention is clear: exception details are irrelevant
echo “You don’t have permission to do this”;
}

Footnotes

[fn:rfc]https://wiki.php.net/rfc/non-capturing\_catches