php.net |  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
 [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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-30 12:38 UTC] stas@php.net
Analysis:
this seems to be due to recent change by iliaa:
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.732&r2=1.733&ty=u

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] 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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 16:01:29 2024 UTC