PHP :: Bug #35022 :: key() malfunctions on references

Bug #35022 key() malfunctions on references
Submitted: 2005-10-30 12:36 UTC Modified: 2005-10-30 19:04 UTC
From: stas at zend dot com Assigned: iliaa (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-10-30 (CVS) OS: *
Private report: No CVE-ID: None

 [2005-10-30 12:36 UTC] stas at zend dot com

Description:
------------
Consider the code below:

it does not produce correct results on 4.4, 5.1 head, but worked in some 5.0 versions due to the fact that key() is defined as by-ref function in 5.0. 

Reproduce code:
---------------
<?
$state = array("one" => 1, "two" => 2, "three" => 3);
function foo( &$state ) {
    $contentDict = end( $state );
    for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) {
        echo key($state)."\n";
    }
}
foo($state);
?>


Expected result:
----------------
three two one

Actual result:
--------------
one one one

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2005-10-30 19:04 UTC] iliaa@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.