Currently, PHP requires all catch statements to specify an Exception class and an identifier variable. This RFC proposes new language constructs to make the variable optional, and to have a fully anonymous catch-statement.

With the recent addition of the finally keyword for try-catch statements, PHP is now in line with many other languages such as C#, Python and Ruby (and probably many others). Those languages differ from PHP in that they don't require a variable to bind the exception in, and don't even require specifying a certain Exception class.

Thus, this RFC proposes to add syntax support for:

try { $this -> connectToServer ( ) ; } catch ( ConnectionLostException ) { $this -> retry ( 3 ) ; }

In this case, we don't need the exception object itself as the exception type is descriptive enough of what happened, and we do not need to log anything because the operation is tried again in 3 seconds. By not specifying a variable, we avoid the impression that we do actually need it. It also helps static analysis tools (e.g. as implemented in IDEs) more accurately discover unused variables.

We can take this one step further, to also get rid of the class:

try { $this -> connectToServer ( ) ; } catch { $this -> retry ( 3 ) ; }

This again avoids the impression that only a specific exception is catched, where currently the least-specific Exception is used in many catch-statements, giving the indication that the handler is only for a specific type of exception, while it's not.

Note that there may only be one anonymous catch-statement, and it has to be the last one.