Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:969 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16264 invoked from network); 19 Apr 2003 02:18:36 -0000 Received: from unknown (HELO asuka.prohost.org) (24.112.18.98) by pb1.pair.com with SMTP; 19 Apr 2003 02:18:36 -0000 Received: (qmail 24794 invoked from network); 18 Apr 2003 21:18:30 -0000 Received: from rei.nerv (HELO dummy.com) (rei@192.168.1.1) by asuka.nerv with SMTP; 18 Apr 2003 21:18:30 -0000 Reply-To: ilia@prohost.org To: internals@lists.php.net Date: Fri, 18 Apr 2003 22:22:09 -0400 User-Agent: KMail/1.5 Organization: Prohost.org MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_RLLo+JW5P/WlZXz" Message-ID: <200304182222.09427.ilia@prohost.org> Subject: Copying of arrays From: ilia@prohost.org ("Ilia A.") --Boundary-00=_RLLo+JW5P/WlZXz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Bug #23195 demonstrates an interesting in the way arrays are copied in PHP. If inside the code that depends on the position of the array the array is copied to another variable it's internal position gets reset. This, as the example below will show will cause an unterminated loop. The source of the problem could be traced to zend_hash_copy(), which will always reset the internal pointer of the target array to the 'head' element. This can be remedied by setting the internal pointer of the new array to the same as the source array, which solves the problem (patch attached). Or we document this problem and tell people to assign values by reference if they need to assign an array, which is being traversed to another variable. Ilia --Boundary-00=_RLLo+JW5P/WlZXz Content-Type: text/plain; charset="us-ascii"; name="zh.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="zh.txt" Index: Zend/zend_hash.c =================================================================== RCS file: /repository/Zend/zend_hash.c,v retrieving revision 1.87.4.2 diff -u -3 -p -r1.87.4.2 zend_hash.c --- Zend/zend_hash.c 31 Dec 2002 16:23:02 -0000 1.87.4.2 +++ Zend/zend_hash.c 19 Apr 2003 02:12:20 -0000 @@ -790,7 +790,7 @@ ZEND_API void zend_hash_copy(HashTable * } p = p->pListNext; } - target->pInternalPointer = target->pListHead; + target->pInternalPointer = source->pInternalPointer; } --Boundary-00=_RLLo+JW5P/WlZXz--