php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4753 in_array matches string vars as integers
Submitted: 2000-06-01 12:38 UTC Modified: 2000-06-01 15:53 UTC
From: patrick at spacesurfer dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Release Candidate 1 OS: linux 2.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: patrick at spacesurfer dot com
New email:
PHP Version: OS:

 

 [2000-06-01 12:38 UTC] patrick at spacesurfer dot com
I am running:
Apache/1.3.12 (Unix) mod_perl/1.21 PHP/4.0RC1 mod_ssl/2.6.2 OpenSSL/0.9.5

The problem is that in_array matches string vars as integer vars, for example the following code will work incorrectly:

$a[0]="001";
$a[1]="003";
if (in_array("1", $a))
 {
 echo "As if<br>";
 }

This is a big problem since it will cause the following code to produce an error:

$HAObjects["0011"]=$Object;
$HAObjects["0131"]=$Object;

if (in_array("11", array_keys($HAObjects)))
 {
 $O=$HAObject["11"];
 $O->SomeFunction();
 }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-06-01 15:53 UTC] andrei at cvs dot php dot net
in_array() has been updated to take third argument which indicates
whether to do strict comparison or not.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC