php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54574 is_array doesn't have any warning about unexpected type casting
Submitted: 2011-04-20 06:21 UTC Modified: 2011-04-20 16:03 UTC
Votes:3
Avg. Score:2.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: ss23 at ss23 dot geek dot nz Assigned: dtajchreber (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2011-04-20 06:21 UTC] ss23 at ss23 dot geek dot nz
Description:
------------
Consider:

$safeColors = array(1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e','f');
var_dump(in_array('T', $safeColors));

People not paying attention would assume "false", however, because T is compared 
with integers, it seems to be cast to 0, therefore, outputting true.

A "solution" would be a warning on the in_array page, as this isn't a problem with 
the function, just something that confuses users who aren't expecting it.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-20 15:58 UTC] dtajchreber@php.net
Automatic comment from SVN on behalf of dtajchreber
Revision: http://svn.php.net/viewvc/?view=revision&revision=310392
Log: Fixed #54574 - clarified that in_array uses loose comparison by default
 [2011-04-20 16:00 UTC] dtajchreber@php.net
Automatic comment from SVN on behalf of dtajchreber
Revision: http://svn.php.net/viewvc/?view=revision&revision=310394
Log: Fixing mistake made with last commit (#54574)
 [2011-04-20 16:02 UTC] dtajchreber@php.net
Added a blurb that in_array uses loose comparison unless $strict is set and the 
default value for the strict parameter is false.
 [2011-04-20 16:03 UTC] dtajchreber@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: dtajchreber
 [2011-04-20 16:03 UTC] dtajchreber@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:08 UTC] phpdocbot@php.net
Automatic comment on behalf of dtajchreber
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a59197ab9f3a7be3afa5d086abd5973087fd7b71
Log: Fixed #54574 - clarified that in_array uses loose comparison by default
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 01:00:02 2026 UTC