I'm so very confused.
What do you make of this code?
<?php
// false.php
$testResultString = "isset: as string: [%s]; as binary: [%b]; null: [%b]; type: [%s]; null equiv: [%b]<br>";
$does = true;
$set = isset($does);
echo sprintf($testResultString, $set , $set, is_null($set), gettype($set), $set == null);
$set = isset($doesNot);
echo sprintf($testResultString, $set , $set, is_null($set), gettype($set), $set == null);
This outputs:
isset: as string: [1]; as binary: [1]; null: [0]; type: [boolean]; null equiv: [0]
isset: as string: []; as binary: [0]; null: [0]; type: [boolean]; null equiv: [1]
Observations:
isset()
returns1
fortrue
and (possibly)null
forfalse
. It was this that was pissing me off on the weekend and stimulated me to write "PHP: a fractal of [etc]... yeah, I'm now getting where you're coming from". This would be like a CFML function returning"Yes"
fortrue
and0
forfalse
. Surely if there was any concern for detail, it'd betrue
/false
or1
/0
(or0
/-1
etc)? It's one thing - as Sean reminded me - fornull
to be interpreted asfalse
, but for it to actually be used as afalse
value seems a bit incoherent to me.- But the value returned is not null, if it's checked for nullness.
- If it's checked for type, it's a boolean
- And if it's compared to
null
, it is null
Huh?
--
Adam