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

Negating An Assignation

<?php

// $e contains the check
!$e = checkSomething();

// $e contains the check,
// and the condition still passes
if (!$e = checkSomething()) {
    print "Something was wrong!";
}

I always wondered why PHP allows to NOT a variable on the LEFT side of an assignation.

It makes sense with an iffectation (an assignation within an if)

I’m sure other such expressions are possible, with unary operators.

Definitely not for me, for readability reasons; same as !$o instanceof X.

See Also

PHP Features

Last updated: 10 September 2026