|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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
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: stas at zend dot com
New email:
PHP Version: OS:


 [2005-10-30 12:36 UTC] stas at zend dot com
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";

Expected result:
three two one

Actual result:
one one one


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-30 12:38 UTC]
this seems to be due to recent change by iliaa:

and due to the following things:

1. key() is now declared as by-value function, so it takes argument via SEND_VAR
2. SEND_VAR separates references
3. separating uses zend_hash_copy
4. zend_hash_copy resets internal pointer

 [2005-10-30 19:04 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-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 15:03:37 2021 UTC