Bug #16227 Updated: Using internal hash position is tricky.

From: Date: Sat, 23 Mar 2002 12:10:08 +0000
Subject: Bug #16227 Updated: Using internal hash position is tricky.
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-3195@lists.php.net to get a copy of this message
ID: 16227 Updated by: yohgaki@php.net -Summary: Wrong zval allocation? while(list() = each()) behavior is inconsistent due to th Reported By: php.net@alienbill.com -Status: Bogus +Status: Open -Bug Type: Arrays related +Bug Type: Documentation problem Operating System: ANY -PHP Version: 4.2.0-dev +PHP Version: PHP4 only New Comment: Ok. Then this is documentation problem. (I would like to hear from Andi or Zeev, though) There should be note that internal hash position is reset if value is assigned. (Both LVALUE and RVLAUE. They are the same value anyway.) Also, reference counting side effect should be documented fully. BTW, to fix this misbihavior, we need a additional variable to keep track of hash position for each zval. (and change related codes) PHP3 does not have problem, since it does not have reference counting. Previous Comments: ------------------------------------------------------------------------ [2002-03-23 06:46:24] derick@php.net It's not a flaw, it's designed like this. Derick ------------------------------------------------------------------------ [2002-03-23 06:39:14] yohgaki@php.net Derick, foreach() does not solve this bug. ZendEngine is resetting internal hash position by an assignment. Therefore, foreach() does does not work. i.e. The issue is _not_ "Not resetting hash posisiton", but "Incorrectly resetting RVALUE hash position by an assignment". This is serious flaw in language. ------------------------------------------------------------------------ [2002-03-23 06:01:49] derick@php.net Not a bug, but intended behavior. Use foreach(). Derick ------------------------------------------------------------------------ [2002-03-22 20:55:39] yohgaki@php.net BTW, I haven't check the exact behavior. Zend might be resetting internal hash position due to the assignment. ------------------------------------------------------------------------ [2002-03-22 20:48:18] yohgaki@php.net I forgot about reset() since behavior is inconsistent :( Anyway, this is still not right. Zend engine is allocating new zval for $insidearray while it should allocate $placeholder. --- $placeholder = $insidearray; while(list(,$innerval) = each($insidearray)){ print "inloop $innerval for $outerval<br>"; --- This bug causes nasty bug in script. If it is not easy to fix, may be we should suspend this bug? ------------------------------------------------------------------------ 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

« previous php.bugs (#3195) next »