php.net |  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
Votes:7
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
Status: Closed Package: Arrays related
PHP Version: 5.2.1 OS: MaxOsX/RedHat
Private report: No CVE-ID:
 [2007-02-16 15:24 UTC] alex dot killing at gmx dot de
Description:
------------
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:
---------------
<?php

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

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

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


?>

Expected result:
----------------
-0-
-0-

Actual result:
--------------
-0-
--

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

Also tested it against the 5.2 snapshot (php5.2-win32-200703191630.zip) from php.net, on WinXP, and the problem seems to still exist.
 [2007-07-14 10:13 UTC] jani@php.net
See also bug #41372

 [2007-07-24 19:26 UTC] dmitry@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 03:02:42 2014 UTC