|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-12-15 23:15 UTC] cardinal at dodds dot net
After using print_r() on an array, the array pointer isn't reset. Affects 4.0.3pl1 and 4.0.4 CVS. $arr['a'] = 'Apple'; $arr['b'] = 'Banana'; $arr['c'] = 'Corn'; print_r($arr); //reset($arr); while(list($k,$v) = each($arr)) echo "$k => $v\n"; PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 21:00:01 2025 UTC |
In retrospect, the proper thing for print_r to do would be to preserve the array's internal pointer, rather than reset it. This patch seems to do the job. Index: zend.c =================================================================== RCS file: /repository/Zend/zend.c,v retrieving revision 1.102 diff -u -r1.102 zend.c --- zend.c 2000/11/02 23:17:55 1.102 +++ zend.c 2000/12/18 00:35:28 @@ -79,6 +79,7 @@ { zval **tmp; char *string_key; + Bucket *internal_pointer; unsigned long num_key; int i; @@ -87,6 +88,7 @@ } ZEND_PUTS("(\n"); indent += PRINT_ZVAL_INDENT; + internal_pointer = ht->pInternalPointer; zend_hash_internal_pointer_reset(ht); while (zend_hash_get_current_data(ht, (void **) &tmp) == SUCCESS) { for (i=0; i<indent; i++) { @@ -112,6 +114,7 @@ ZEND_PUTS(" "); } ZEND_PUTS(")\n"); + ht->pInternalPointer = internal_pointer; }