From: lenar at city dot ee Operating system: Debian PHP version: 4.3.9 PHP Bug Type: Scripting Engine problem Bug description: in_array not working correctly
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 bug report at http://bugs.php.net/?id=30473&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30473&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30473&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30473&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30473&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30473&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30473&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30473&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30473&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30473&r=support Expected behavior: http://bugs.php.net/fix.php?id=30473&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30473&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30473&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30473&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30473&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30473&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30473&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30473&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30473&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30473&r=mysqlcfg