1.2.857. Not Not

Double not makes a boolean, not a true.

This is a wrong casting to boolean. PHP supports (boolean) to do the same, faster and cleaner.

<?php
    // Explicit code
    $b = (boolean) $x;
    $b = (bool) $x;

    // Wrong type casting
    $b = !!$x;

?>

See also Logical Operators and Type Juggling.

1.2.857.1. Suggestions

  • Use (bool) casting operator for that

  • Don’t typecast, and let PHP handle it. This works in situations where the boolean is immediately used.

1.2.857.2. Specs

Short name

Structures/NotNot

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

logical-operator, cast

ClearPHP

no-implied-cast

Examples

Cleverstyle, Tine20

Available in

Entreprise Edition, Community Edition, Exakat Cloud