ID: 16227 Comment by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Documentation problem Operating System: ANY PHP Version: PHP4 only New Comment:
Well, so is it fixed or is it not? This bug's status is still Open. Previous Comments: ------------------------------------------------------------------------ [2002-10-01 06:28:18] [EMAIL PROTECTED] FYI. The bug is fixed. Current CVS version does not swap internal hash position on assinment. ------------------------------------------------------------------------ [2002-10-01 06:13:17] [EMAIL PROTECTED] The issue is ZendEngine mess up hash position by assignment. I'll open new one for this. ------------------------------------------------------------------------ [2002-07-16 11:22:34] [EMAIL PROTECTED] each() as a function does not know in which context it was called so it just returns the 'current' element and advances the internal position pointer, very similar to the java next_element() iterator (hope i got the name right). when no more elements are left it returns false until being reset each() can not know that it was called from different loop runs so it will return false forever until reset. one might think about auto-reseting it after returning false once, but backwards compatibility will be in our way once again here the problem does not happen this way in java because there next_element() advances the internal pointer before returning values and you have to use first_element() to get the first one (which implies a reset) foreach uses a private copy of the array structure so it has its own internal pointer which is recreated for every foreach instance so the problem does occure here ------------------------------------------------------------------------ [2002-03-23 20:44:45] [EMAIL PROTECTED] Oops, $arr = array('a', 'b', 'c'); does reset position :) ------------------------------------------------------------------------ [2002-03-23 20:39:56] [EMAIL PROTECTED] Both each() and foreach() uses internal hash position variable. Difference is foreach() reset internal hash position to the first element while each() does not. A problematic behavior is an assignment resets internal hash position. There are other cases programmer has to be careful about internal hash position and reference counting feature. In addition to that, it is _not_ intuitive that assignment as follows $arr = array('a', 'b', 'c'); does not reset hash posiiton, while following assignment does reset hash position. $arr2 = $arr1; Anyway, some internal hash posision behaviors are inconsistent and _not_ intuitive at all. This would be really hard to find if a user experience the problem. Therefore, it should be documented :) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/16227 -- Edit this bug report at http://bugs.php.net/?id=16227&edit=1 -- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php