php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63226 Mixed array index iteration has broken key=>value pair
Submitted: 2012-10-05 16:47 UTC Modified: 2012-10-05 17:13 UTC
From: nicholas dot puleo at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.7 OS: Ubuntu 12.0.4.1 LTS
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: nicholas dot puleo at gmail dot com
New email:
PHP Version: OS:

 

 [2012-10-05 16:47 UTC] nicholas dot puleo at gmail dot com
Description:
------------
If getting an array with mixed index types (in this case it was served from LDAP) 
- iterating over using a foreach loop yielded incorrect key values on the first 
changed index from associative to numerical.

Test script:
---------------
<?php
$d = array();
$d['text'] = 1;
$d[0] = 1;
$d[1] = 2;

foreach ($d as $k=>$v) {
	if ($k == "text") { 
		echo 'Should Only See Once';
		} else {
		echo $v;
		}
}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-05 17:13 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2012-10-05 17:13 UTC] nikic@php.net
0 == "text", that's why you see it twice. If you want a strict string check use $k === "text".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 13:01:31 2024 UTC