ID: 30473 Updated by: [EMAIL PROTECTED] Reported By: lenar at city dot ee -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Debian PHP Version: 4.3.9 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php There is no BC here, I tried a couple of versions (4.0.0, 4.0.7, 4.1.2, 4.2.3, 4.3.5-4.3.9) and all do this: [EMAIL PROTECTED]:/dat/dev/php/php-4.0.0$ ./php <?php var_dump(in_array("test", array(0))); ?> X-Powered-By: PHP/4.0.0 Content-type: text/html bool(true) Previous Comments: ------------------------------------------------------------------------ [2004-10-18 18:46:24] lenar at city dot ee Description: ------------ function in_array() returns wrong result. No way (string) "test" is equal to (int) 0. It is not right to cast needle to the type of array value. The same problem manifests itself with array_search(). You will say propably that you've added third parameter to in_array() to take care of this, but in reality this isn't solution. The problem is you can't blindly cast needle. And manual says: If needle is a string, the comparison is done in a case-sensitive manner. Now tell me how you can compare a string you cast to (int) in case-sensitive manner? And this is all bad because I discovered this by accident after a customer complained their stuff didn't work anymore. That code used to work. I can swear. So you have broken BC it seems. Reproduce code: --------------- var_dump(in_array("test", array(0)) Expected result: ---------------- bool(false) Actual result: -------------- bool(true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30473&edit=1