Answer the question
In order to leave comments, you need to log in
PHP behaves strangely when comparing null and "*"
I'm shocked by php ... Maybe I don't understand something, I didn't find anything in Google. Please run this code:
$a = '0';
$b = 0;
$c = '1';
$d = 1;
if($a == '*') echo 'A = *;<br />';
if($b == '*') echo 'B = *;<br />';
if($c == '*') echo 'C = *;<br />';
if($d == '*') echo 'D = *;<br />';
When compared via == null (precisely int type) with the string '*', it returns TRUE.
Comparison through === and null string ('0') gives FALSE
Answer the question
In order to leave comments, you need to log in
So coercion of types. The right argument is cast to the type of the left argument. Those. '*' is cast to 0, which becomes 0 accordingly.
And this is not only with *, but with anything other than digital. Try a, b, +, etc.
you can try
$a = *;
if ($a == strval(0))
In general, I am for variable typing. In 5.4, they have already begun to do this. I'm looking forward to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question