1.2.1455. Yoda Comparison

Yoda comparison is a way to write conditions which places literal values on the left side.

The objective is to avoid mistaking a comparison to an assignation. If the comparison operator is mistaken, but the literal is on the left, then an error will be triggered, instead of a silent bug.

.

<?php
  if (1 == $a) {
    // Then condition
  }
?>

See also Yoda Conditions and Yoda Conditions: To Yoda or Not to Yoda.

1.2.1455.1. Specs

Short name

Structures/YodaComparison

Rulesets

All, Coding conventions

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud