Bug #62901 [Asn->Csd]: foreach unexpectedly advances the internal array pointer

From: Date: Tue, 31 Jan 2017 11:00:31 +0000
Subject: Bug #62901 [Asn->Csd]: foreach unexpectedly advances the internal array pointer
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207066@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62901&edit=1 ID: 62901 Updated by: nikic@php.net Reported by: david at grudl dot com Summary: foreach unexpectedly advances the internal array pointer -Status: Assigned +Status: Closed Type: Bug Package: Variables related PHP Version: 5.4.6 Assigned To: laruence Block user comment: N Private report: N New Comment: Closing as this has been fixed in PHP 7 and PHP 5 is no longer actively supported. Previous Comments: ------------------------------------------------------------------------ [2015-06-10 13:37:27] arjen at react dot com This is fixed in 7.0, still fails in 5.5, 5.6. Created a different testcase: http://3v4l.org/jH4pM When the return value is assigned to a tmp var first, the internal pointer isn't modified. ------------------------------------------------------------------------ [2012-09-14 02:56:51] laruence@php.net @nikic, after we discussed yesterday, I re-through the codes, do find a *inconsistent* place, assign to myself, thanks ------------------------------------------------------------------------ [2012-09-13 16:19:15] nikic@php.net @laruence: Changing the array pointer is a change too. That's why foreach usually copies the passed array. So yes, this is a bug, but from a quick glance at the code I can't yet see why it happens. ------------------------------------------------------------------------ [2012-09-13 02:45:16] laruence@php.net s ,write on copy, copy on write, ;< ------------------------------------------------------------------------ [2012-09-13 02:44:38] laruence@php.net the same, although it is *copy* of a array, but still the same zval, PHP using "write on copy". but the internalPointer's change is not considered as "write" here. ------------------------------------------------------------------------ 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 https://bugs.php.net/bug.php?id=62901 -- Edit this bug report at https://bugs.php.net/bug.php?id=62901&edit=1

« previous php.bugs (#207066) next »