|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40509 key() function changed behaviour if global array is used within function
Submitted: 2007-02-16 15:24 UTC Modified: 2007-07-24 19:26 UTC
Avg. Score:4.9 ± 0.3
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:1 (16.7%)
From: alex dot killing at gmx dot de Assigned: dmitry (profile)
Status: Closed Package: Arrays related
PHP Version: 5.2.1 OS: MaxOsX/RedHat
Private report: No CVE-ID: None
 [2007-02-16 15:24 UTC] alex dot killing at gmx dot de
If a global array is assigned to a local variable as in the example, and the local variable is iterated afterwards, the key() function changed the behaviour in the global scope with PHP 5.2.1.

Reproduce code:

function foo()
	global $arr;
	$c = $arr["v"];
	foreach ($c as $v) {}

$arr["v"] = array("a");

echo "-".key($arr["v"])."-";	// prints "0"
echo "<br/>-".key($arr["v"])."-";	// prints "" since 5.2.1 ("0" on all prior versions)


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-19 19:59 UTC]
Tested this example against the 5.2.1 zipfile from on WinXP and the problem does occur.

Also tested it against the 5.2 snapshot ( from, on WinXP, and the problem seems to still exist.
 [2007-07-14 10:13 UTC]
See also bug #41372

 [2007-07-24 19:26 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC