PHP 4.0 Bug #8289 Updated: print_r doesn't reset() arrays
| From: | stas@php.net | Date: | Mon, 18 Dec 2000 13:58:27 +0000 |
| Subject: | PHP 4.0 Bug #8289 Updated: print_r doesn't reset() arrays | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-41744@lists.php.net to get a copy of this message | ||
ID: 8289
Updated by: stas
Reported By: cardinal@dodds.net
Old-Status: Open
Status: Closed
Bug Type: Arrays related
Assigned To:
Comments:
Fixed in CVS, thanks.
Previous Comments:
---------------------------------------------------------------------------
[2000-12-17 19:37:00] cardinal@dodds.net
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;
}
---------------------------------------------------------------------------
[2000-12-15 23:15:20] cardinal@dodds.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 => $vn";
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8289