PHP RFC: non-capturing catches


Currently, PHP requires to capture the exception being caught to a variable:

try {
} catch (SomeException $ex) {

However, you need to specify the variable even if it's not used:

try {
} catch (PermissionException $ex) {
    echo "You don't have permission to do this";

Someone reading the above code is left to wonder if the author intended to not use the exception variable or it's a bug.


Allow catching exceptions without capturing them to variables:

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

Prior art

Such change was first proposed in this RFC 7 years ago. It was turned down mostly because it also wanted to allow blanket catches like this:

try {
} catch {

Meanwhile what I'm proposing here has received mostly positive feedback so I feel it's worth revisiting.

Backward Incompatible Changes


Proposed PHP Version(s)


RFC Impact



Voting started on 2020-05-10 and will end on 2020-05-24 at 9:00 UTC.

Accept this RFC?
Real name Yes No
alcaeus (alcaeus)  
asgrim (asgrim)  
ashnazg (ashnazg)  
beberlei (beberlei)  
bmajdak (bmajdak)  
bwoebi (bwoebi)  
carusogabriel (carusogabriel)  
cmb (cmb)  
dams (dams)  
dmitry (dmitry)  
duncan3dc (duncan3dc)  
ekin (ekin)  
galvao (galvao)  
geekcom (geekcom)  
jasny (jasny)  
jbnahan (jbnahan)  
jhdxr (jhdxr)  
kalle (kalle)  
kelunik (kelunik)  
kguest (kguest)  
kocsismate (kocsismate)  
levim (levim)  
lstrojny (lstrojny)  
marandall (marandall)  
marcio (marcio)  
mariano (mariano)  
mbeccati (mbeccati)  
mcmic (mcmic)  
mike (mike)  
nicolasgrekas (nicolasgrekas)  
nikic (nikic)  
ocramius (ocramius)  
pierrick (pierrick)  
pmjones (pmjones)  
pmmaga (pmmaga)  
pollita (pollita)  
rtheunissen (rtheunissen)  
ruudboon (ruudboon)  
salathe (salathe)  
santiagolizardo (santiagolizardo)  
sergey (sergey)  
sirsnyder (sirsnyder)  
svpernova09 (svpernova09)  
tandre (tandre)  
trowski (trowski)  
wjx (wjx)  
wyrihaximus (wyrihaximus)  
yunosh (yunosh)  
zimt (zimt)  
Final result: 48 1
This poll has been closed.

Patches and Tests


After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)


* https://externals.io/message/109550 - initial announcements

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/non-capturing_catches.txt · Last modified: 2020/05/26 14:39 by maxsem