Bug #14343 Updated: in_array wrongly matches zero

From: Date: Tue, 04 Dec 2001 21:00:21 +0000
Subject: Bug #14343 Updated: in_array wrongly matches zero
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-72507@lists.php.net to get a copy of this message
ID: 14343 User updated by: davidw@ensky.com Reported By: davidw@ensky.com Status: Bogus Bug Type: Arrays related Operating System: Linux/PPC PHP Version: 4.0.5 New Comment: Doh! I should have known that. Previous Comments: ------------------------------------------------------------------------ [2001-12-04 15:49:37] derick@php.net Not a bug... PHP indeed tries to convert 'foobar' to a number, and because that is not really possible, it becomes 0. That's why there is that third parameter too. Derick ------------------------------------------------------------------------ [2001-12-04 15:37:18] davidw@ensky.com On my system, in_array wrongly returns true when searching for zero in arrays that don't contain zero: Sample code: in_array(0, array('foobar')); -->TRUE If I add the third parameter, it returns the correct result: print in_array(0, array('foobar'), true); -->FALSE However, I'm pretty sure that 0 doesn't coerce to 'foobar' - I don't think PHP is that loosely-typed :) ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14343&edit=1

« previous php.dev (#72507) next »