I have noticed if a value is null
i can increment it by one using ++$value
but its not true about decrement , meaning --$value
would return null
, why?
$value = null;
echo ++$value; // 1
echo --$value; // null (I'm expecting -1)
Ref# language.operators.increment.php
Note: The increment/decrement operators only affect numbers and strings. Arrays, objects and resources are not affected. Decrementing NULL values has no effect too, but incrementing them results in 1.
Think about it in a logical sense.
You can't take something away from nothing, but you can add something to nothing. Null is not 0, it is simply no value.