#50472 [Bgs]: in_array documentation should indicate casting of array elements
| From: | bjori@php.net | Date: | Mon, 14 Dec 2009 20:47:05 +0000 |
| Subject: | #50472 [Bgs]: in_array documentation should indicate casting of array elements | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3474@lists.php.net to get a copy of this message | ||
ID: 50472
Updated by: bjori@php.net
Reported By: llahwehttam at gmail dot com
Status: Bogus
Bug Type: Documentation problem
Operating System: Linux
PHP Version: 5.2SVN-2009-12-14 (snap)
New Comment:
#fail :)
http://php.net/types.comparisons
Sorry :)
Previous Comments:
------------------------------------------------------------------------
[2009-12-14 20:46:35] bjori@php.net
http://php.net/types.comparisons.php
We can't link to that from all functions.
------------------------------------------------------------------------
[2009-12-14 19:39:46] llahwehttam at gmail dot com
Description:
------------
in_array(0, array("a")) returns true. This is very much unexpected
behavior for someone learning PHP.
I see a unit test on line 38 of
ext/standard/tests/array/in_array_variation4.phpt explicitly confirming
this behavior.
As mentioned in [14343], the current documentation does not indicate
the array elements will be cast to the type of the needle. The
description of the 'strict' parameter does not indicate why it may be
necessary to use it. Adding the following text to the in_array function
description would help:
'in_array casts the elements of the array to the type of the first
parameter.'
Further helpful text would be:
'If you are searching for a number in an array of strings, each string
will be cast to a number. If this is not desired behavior pass "strict"
as true.'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50472&edit=1