Skip to content

[New Rule] The use of literal logical operators MUST be avoided #23

Closed
@lenaorobei

Description

@lenaorobei

Rule

The use of literal logical operators (and, or) is discouraged. && and || should be used instead.

Reason

Operator precedence is different for and vs. && and or vs. ||.
It may cause unexpected behaviour:

$x = false || true;  // is ($x = (false || true)) => true
$x = false or true;  // is (($x = false) or true) => false
    
$x = true && false;  // is ($x = (true && false)) => false
$x = true and false; // is (($x = true) and false) => true

Please use the official documentation for more details.

Implementation

Add Squiz.Operators.ValidLogicalOperators to the ruleset.xml.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions