php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50472 in_array documentation should indicate casting of array elements
Submitted: 2009-12-14 19:39 UTC Modified: 2009-12-14 20:47 UTC
From: llahwehttam at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2SVN-2009-12-14 (snap) OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: llahwehttam at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-14 19:39 UTC] 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.'


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-14 20:46 UTC] bjori@php.net
http://php.net/types.comparisons.php

We can't link to that from all functions.
 [2009-12-14 20:47 UTC] bjori@php.net
#fail :)
http://php.net/types.comparisons

Sorry :)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 09:00:02 2026 UTC