#50472 [NEW]: in_array documentation should indicate casting of array elements
| From: | llahwehttam at gmail dot com | Date: | Mon, 14 Dec 2009 19:39:46 +0000 |
| Subject: | #50472 [NEW]: in_array documentation should indicate casting of array elements | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-3472@lists.php.net to get a copy of this message | ||
From: llahwehttam at gmail dot com
Operating system: Linux
PHP version: 5.2SVN-2009-12-14 (snap)
PHP Bug Type: Documentation problem
Bug description: in_array documentation should indicate casting of array elements
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 bug report at http://bugs.php.net/?id=50472&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50472&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50472&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50472&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50472&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50472&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50472&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50472&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50472&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50472&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50472&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50472&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50472&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50472&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50472&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50472&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50472&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50472&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50472&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50472&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50472&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50472&r=mysqlcfg