php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48362 documentation for in_array should honor type conversion
Submitted: 2009-05-22 11:38 UTC Modified: 2009-05-22 16:13 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jketterl at chipxonio dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
 [2009-05-22 11:38 UTC] jketterl at chipxonio dot de
Description:
------------
the in_array() function apparently converts the given $needle and all members of $haystack to int when the third parameter is left out / false (see also http://bugs.php.net/bug.php?id=37235).

since this seems to be expected behaviour (which i disagree about, but that's not the point here) it should be explicitly documented on the corresponding manual page.

background: the conversion basically makes the function useless for string keys without strict comparison since they will convert to zero most of the time.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-22 16:13 UTC] lbarnaud@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is how comparison is done by default in PHP and this do not need to be documented for every function.

When comparing a string to a string, if both represent a number, they are compared as numbers. This is what allows you to do things like ($_GET['foo'] > $_GET['bar']) without taking care of types.

Strict comparison can be used instead.

<?php
("+36901112222" == "36901112222") === true // loose comparison
("+36901112222" === "36901112222") === false // strict comparison
?>

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC