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)

Hi @Bastien_SANDER,

Welcome to the community. Thank you for your report.
Your case has led to some internal discussion about whether this is a clean way to check the format of an input value. We have come to the conclusion that we want to allow this. For this reason, I have created the following ticket, which we will implement in one of the next iterations.

Thank you for your contribution.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.