php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29421 array_search confusions
Submitted: 2004-07-28 08:26 UTC Modified: 2004-08-23 19:20 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: redeye at erisx dot de Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.0.0 OS: *
Private report: No CVE-ID: None
 [2004-07-28 08:26 UTC] 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) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-07 13:44 UTC] 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-08-23 19:20 UTC] iliaa@php.net
appears to be properly documented now. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 21:01:30 2024 UTC