php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8289 print_r doesn't reset() arrays
Submitted: 2000-12-15 23:15 UTC Modified: 2000-12-18 08:58 UTC
From: cardinal at dodds dot net Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0 Latest CVS (15/12/2000) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cardinal at dodds dot net
New email:
PHP Version: OS:

 

 [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";

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-17 19:37 UTC] cardinal at dodds dot 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-18 08:58 UTC] stas@php.net
Fixed in CVS, thanks.
 [2012-12-14 04:42 UTC] googleguy@php.net
Automatic comment from SVN on behalf of googleguy
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328776
Log: Removed mention of print_r reseting array's internal pointer. This is not the current behavior. See bug #8289 for more information.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC