#29421 [Ver->Csd]: array_search confusions

From: Date: Mon, 23 Aug 2004 17:20:54 +0000
Subject: #29421 [Ver->Csd]: array_search confusions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65108@lists.php.net to get a copy of this message
ID: 29421 Updated by: iliaa@php.net Reported By: redeye at erisx dot de -Status: Verified +Status: Closed Bug Type: Arrays related Operating System: * PHP Version: 5.0.0 New Comment: appears to be properly documented now. Previous Comments: ------------------------------------------------------------------------ [2004-08-07 13:44:46] andrey@php.net This will be more or less "Won't Fix" since it relies on the internal zend function for type comparison and according to the type juggling rules of PHP this is valid but not straight forward for anyone (even for me). ------------------------------------------------------------------------ [2004-07-28 08:26:44] redeye at erisx dot de Description: ------------ When using array_search with strict set to FALSE will allways return the first matching element of an array, which is absolutly correct, but will also match every (boolean) TRUE value of an array (which is bad). This way, you could either hope no value is set to (boolean) TRUE or are forced to enable strict, which is not allways desired. This behavoir should either be better documented ( as is the behavior of FALSE ( "" , 0 , -1 , FALSE ) or changed to only match against ( "1" , 1 , "TRUE" , TRUE ). Reproduce code: --------------- $array = array ( 'foo' , TRUE , 'bar' ) ; $search = array_search ( 'baz' , $array ) ; var_dump ( $search ) ; Expected result: ---------------- bool(false) Actual result: -------------- int(1) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29421&edit=1

« previous php.bugs (#65108) next »