1.2.535. Identical Elseif

In a long if/elseif/then structures, identical conditions are mutually exclusive. The first one will happen, and the second will be ignored.

This is similar to having multiple cases in the same switch or match expression.

<?php

if ($a === 1) { }
elseif ($a === 2) { }
elseif ($a === 3) { }
elseif ($a === 4) { }
elseif ($a === 2) { }
else {}

?>

1.2.535.1. Suggestions

  • Remove the extra elseif() clause

  • Fixed the condition of the extra elseif() clause

  • Use a switch() or match() expression

1.2.535.2. Specs

Short name

Structures/IdenticalElseif

Rulesets

All, Dead code

Exakat since

2.3.7

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

if-then

Available in

Entreprise Edition, Exakat Cloud