Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Minus One -1

Minus one is the -1 integer. -1 is part of the truthy values: it is the equivalent of true.

-1 is part of the three values returned by the spaceship operator.

0 is a classic magic number, although it has so many uses that it is usually overlooked, as generating too many false positives or scattered issues.

<?php

    $zero = 0;

    $four = 4 + 0;
    
    // may it returns 1 or -1, this is true
    var_dump((bool) 1 <=> -1); // true
    var_dump((bool) -1 <=> 1); // true

?>

Documentation

See Also