A Non-transitive Comparison

By Gina Peter Banyard

<?php

var_dump('0' == 0);

var_dump('0' == false);
var_dump(0 == false);

// Non transifive
var_dump('0' == null);
var_dump(0 == null);

Sometimes I truly believe that I have grasped all of the weird semantics of PHP, and then I discover something so simple that breaks an assumption I had about the language.

I knew that NAN == X can return true.

I knew that the comparison operators are not transitive.

I obviously knew that "0" == 0 and "0" == false return true.

And yet it was foolish of me to believe that all instance of X == false would give the same answer as X == null.

As TIL "0" == null is false.

See Also

PHP Features

Last updated: 14 July 2026