Can somebody explain how null is mapped in these statements?
null>0; //=> bool(false) null<0; //=> bool(false) null==0; //=> bool(true)
but
null<-1; // => bool(true)
I assume it's some mapping problem, but can't crack it.
Tried with PHP 5.3.5-1 with Suhosin-Patch.
Uses of Null Coalescing Operator: It is used to replace the ternary operator in conjunction with the PHP isset() function. It can be used to write shorter expressions. It reduces the complexity of the program. It does not throw any error even if the first operand does not exist.
In PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value been set to null by using unset() function.
Null coalescing operator ¶ The null coalescing operator ( ?? ) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset(). It returns its first operand if it exists and is not null ; otherwise it returns its second operand. // if it does not exist.
Null-safe operator is a new syntax in PHP 8.0, that provides optional chaining feature to PHP. The null-safe operator allows reading the value of property and method return value chaining, where the null-safe operator short-circuits the retrieval if the value is null , without causing any errors.
I would point you to a few pages: http://php.net/manual/en/types.comparisons.php http://php.net/manual/en/language.operators.comparison.php http://php.net/manual/en/language.types.boolean.php
So in your final example:
null<-1 => bool(true)
The null
is cast to false
and the -1
is cast to true
, false
is less than true
In your first two examples null
is cast to false
and 0
is cast to false
, false
is not less than or greater than false
but is equal to it.
Ohh the fun of null
! :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With