PHP RSPEC-1848 inside a try catch

  • What language is this for? PHP

  • Which rule? PHP RSPEC-1848

  • Why do you believe it’s a false-positive/false-negative?
    In case (see below), the object is created inside a try/catch block,
    In case of a validation function for example, It may be used to check the validity of some variable passed to a constructor.

    • SonarQube - in Developer Edition
    • SonarLint - which IDE/version connected mode with SonarQube
  • Example Code to reproduce:

function isValidDate() {
        try {
            new DateTime($varToTest);
        } catch (Exception $exception) {
            return false;
return true;

Hey there.

What version of SonarQube are you using? This can be found in the footer of your SonarQube instance.


  • Developer Edition
  • Version 10.0 (build 68432)