|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24396 foreach ($k=>$v), the key $k is missing
Submitted: 2003-06-29 23:48 UTC Modified: 2003-06-30 08:48 UTC
From: jlim at natsoft dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0b1 (beta1) OS: Windows XP
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.
Block user comment
Status: Assign to:
Bug Type:
From: jlim at natsoft dot com
New email:
PHP Version: OS:


 [2003-06-29 23:48 UTC] jlim at natsoft dot com
The following script below fails (missing $k).

Reproduce code:

echo PHP_VERSION."<br>";

foreach($_GET as $k=>$v)  {
	global $$k;
	print " ($k=>$v) ";
	$$k = $v;

Expected result:
Array ( [a] => 1 [b] => 2 [c] => 3 ) (a=>1) (b=>2) (c=>3) 

Actual result:
Array ( [a] => 1 [b] => 2 [c] => 3 ) (=>1) (=>2) (=>3) 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-30 05:48 UTC]
Array ( [a] => 1 [b] => 2 [c] => 3 ) (a=>1) (b=>2) (c=>3)

(just checked that this is just 5.0.0b1 issue)

 [2003-06-30 08:46 UTC] sniper at iki dot fi

$arr = array('a' => 1, 'b' => 2, 'c' => 3);

echo PHP_VERSION."<br>";

foreach($arr as $k=>$v)  {
    global $$k; // comment this out and it works in PHP 5 too..
    print " ($k=>$v) ";
    $$k = $v;          
 [2003-06-30 08:48 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 20:01:32 2024 UTC