Posted by Michael Fesser on 12/28/07 17:51
..oO(rynato)
>uh, nevermind. I figured it out. For posterity's sake here's the
>solution:
>
>instead of:
>
>if ($value)
>
>I changed that conditional to:
>
>if ($value != null || $value === 0)
if (!is_null($value)) {
...
} else {
...
}
>the value was passed into the function correctly (it still equalled 0)
>but for some reason 'if ($value)' was not sufficient for PHP to
>distinguish between a value of 0 and no value at all. Can someone
>explain this distinction to me? Thanks.
It's explained in the manual (type juggling).
The 'if' statement always expects a boolean expression. If you just pass
a single variable to it like in your case, its type will automatically
be converted to a boolean (also explained in the manual in more detail).
In short: Zero values, empty strings, empty arrays and NULL always
evaluate to FALSE, anything else to TRUE:
0 == 0.0 == '0' == '' == array() == NULL == FALSE
Micha
[Back to original message]
|