Re: in_array not operating as 'expected'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ing. Ivo F.A.C. Fokkema wrote:
Hi guys and gals,

I'm not screaming "Bug! Bug!" but this _does_ look 'illogical' to me. I've
searched the archives, but found no earlier conversation. Sorry if
I missed it. Consider the following code:

var_dump(in_array('test', array(0)));

What does this return? I expect bool(false), but it returns bool(true).
After some searching the web, I bumped into this:
http://www.phpdiscuss.com/article.php?id=67763&group=php.bugs

Basically, it is said by derick [at] php.net that this behavior is
expected. The following code :

var_dump('test' == 0);

'test' and 0 are not of the same type (string vs int), so string is converted to int, 0. In the examples below no type casting is needed.



also returns bool(true). But my logic tells me, that if 'test' == 0, then :

if (0) {
  ...
}

should do the same as

if ('test') {
  ...
}

but it doesn't! The first if-statement is _not_ executed, the latter is.
In my opinion, this is not correct. Any thoughts on this? Am I not seeing
the logic here?

Thanks for your thoughts.

Ivo Fokkema


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux