php.net |  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
 [2003-06-29 23:48 UTC] jlim at natsoft dot com
Description:
------------
The following script below fails (missing $k).

Reproduce code:
---------------
<?php
error_reporting(E_ALL);

echo PHP_VERSION."<br>";
print_r($_GET);

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

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

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-30 05:48 UTC] sniper@php.net
4.3.3RC2-dev
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
<?php

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

echo PHP_VERSION."<br>";
print_r($arr);

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] zeev@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net 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: Thu Nov 21 08:01:29 2024 UTC