From: Operating system: Any PHP version: 5.3.6 Package: Arrays related Bug Type: Bug Bug description:print_r does not reset() array pointer
Description: ------------ The PHP documentation states: Remember that print_r() will move the array pointer to the end. Use reset() to bring it back to beginning. But after using print_r() on an array, the array pointer is not reset. This is the same as Bug #8289 from PHP 4 in the year 2000: http://bugs.php.net/bug.php?id=8289 Test script: --------------- $arr['a'] = 'Apple'; $arr['b'] = 'Banana'; $arr['c'] = 'Corn'; print_r($arr); //reset($arr); while(list($k,$v) = each($arr)) echo "$k => $v\n"; Expected result: ---------------- Since print_r moves the array pointer to the end I would expect FALSE to be returned by each() and nothing to be printed. However, I also note that foreach() has some side effects so perhaps this is not necessarily a bug but a documentation issue? foreach() notes: http://www.php.net/manual/en/control-structures.foreach.php Note: Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it. Actual result: -------------- Array ( [a] => Apple [b] => Banana [c] => Corn ) a => Apple b => Banana c => Corn -- Edit bug report at http://bugs.php.net/bug.php?id=54931&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54931&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54931&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54931&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54931&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54931&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54931&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54931&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54931&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54931&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54931&r=support Expected behavior: http://bugs.php.net/fix.php?id=54931&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54931&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54931&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54931&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54931&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54931&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54931&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54931&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54931&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54931&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54931&r=mysqlcfg