A catch clause follows one for a parent class and is never reached

tx0/php:unreachable-catchdefaultwarningreliability/error-handlingdepth fastbug

What it finds

catch (Exception $e) { ... } catch (RuntimeException $e) { ... }: catch clauses are tried in order, so a clause for a class after a clause for one of its parents is never reached. Only PHP's own exception classes are known here, so classes declared in the project are not compared.

From the rule's source, unreachable_catch.rs.

Example from the rule's tests
<?phpfunction run(){    try {        work();    } catch (Exception $e) {        log_it($e);    } catch (RuntimeException $e) {tx0 reports: RuntimeException is already caught by an earlier clause        retry();    } catch (TypeError $e) {        fail();    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/php:unreachable-catch" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:unreachable-catch] reason="..."

tx0 explain tx0/php:unreachable-catch shows the same in the terminal. Found a false positive? Report it.