Doc #54574 [Opn]: is_array doesn't have any warning about unexpected type casting
| From: | dtajchreber@php.net | Date: | Wed, 20 Apr 2011 14:02:55 +0000 |
| Subject: | Doc #54574 [Opn]: is_array doesn't have any warning about unexpected type casting | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-6268@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54574&edit=1
ID: 54574
Updated by: dtajchreber@php.net
Reported by: ss23 at ss23 dot geek dot nz
Summary: is_array doesn't have any warning about unexpected
type casting
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Added a blurb that in_array uses loose comparison unless $strict is set
and the
default value for the strict parameter is false.
Previous Comments:
------------------------------------------------------------------------
[2011-04-20 16:00:07] 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 15:58:30] 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 06:21:33] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54574&edit=1