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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat May 17 06:01:26 2025 UTC