#35022 [Asn->Csd]: key() malfunctions on references
| From: | iliaa@php.net | Date: | Sun, 30 Oct 2005 18:04:50 +0000 |
| Subject: | #35022 [Asn->Csd]: key() malfunctions on references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87225@lists.php.net to get a copy of this message | ||
ID: 35022
Updated by: iliaa@php.net
Reported By: stas at zend dot com
-Status: Assigned
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5CVS-2005-10-30 (CVS)
Assigned To: iliaa
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2005-10-30 12:38:22] 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 12:36:32] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35022&edit=1