Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Catch Without Variable

A catch clause doesn’t require a storing variable anymore. It may simply omit it. The exception is then caught, but not provided in the clause.

PHP code

<?php

try {
    throw new Exception('Error');
} catch (Exception) {
    print 'Exception caught';
}

?>

Before

Parse error: syntax error, unexpected ')', expecting '|' or variable (T_VARIABLE)

After

Exception caught

PHP version change

This behavior changed in 8.0.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat