Doc #62914 [NEW]: First entry appears twice, unless rewind method is called first

From: Date: Thu, 23 Aug 2012 22:18:04 +0000
Subject: Doc #62914 [NEW]: First entry appears twice, unless rewind method is called first
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8758@lists.php.net to get a copy of this message
From: lveyde at gmail dot com Operating system: CentOS 6.3 PHP version: 5.3.16 Package: SPL related Bug Type: Documentation Problem Bug description:First entry appears twice, unless rewind method is called first Description: ------------ --- From manual page: http://www.php.net/recursivedirectoryiterator.construct --- I tried to run the sample code (changing the directory), and unless the call to the rewind() method is performed before using the iterator, the first entry appears twice in the output. I'm using PHP version 5.3.3, the latest available with RHEL/CentOS 6.x. <?php $directory = '/root/isos'; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); // Added this $it->rewind(); while($it->valid()) { if (!$it->isDot()) { echo 'SubPathName: ' . $it->getSubPathName() . "\n"; echo 'SubPath: ' . $it->getSubPath() . "\n"; echo 'Key: ' . $it->key() . "\n\n"; } $it->next(); } ?> Is that a normal behavior (and thus bug in the documentation) ? Test script: --------------- <?php $directory = '/root/isos'; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while($it->valid()) { if (!$it->isDot()) { echo 'SubPathName: ' . $it->getSubPathName() . "\n"; echo 'SubPath: ' . $it->getSubPath() . "\n"; echo 'Key: ' . $it->key() . "\n\n"; } $it->next(); } ?> Expected result: ---------------- SubPathName: CentOS-6.2-x86_64-netinstall.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-netinstall.iso SubPathName: CentOS-6.2-x86_64-bin-DVD1.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-bin-DVD1.iso SubPathName: CentOS-6.2-x86_64-LiveCD.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-LiveCD.iso SubPathName: CentOS-6.2-x86_64-bin-DVD2.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-bin-DVD2.iso Actual result: -------------- SubPathName: CentOS-6.2-x86_64-netinstall.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-netinstall.iso SubPathName: CentOS-6.2-x86_64-netinstall.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-netinstall.iso SubPathName: CentOS-6.2-x86_64-bin-DVD1.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-bin-DVD1.iso SubPathName: CentOS-6.2-x86_64-LiveCD.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-LiveCD.iso SubPathName: CentOS-6.2-x86_64-bin-DVD2.iso SubPath: Key: /root/isos/CentOS-6.2-x86_64-bin-DVD2.iso -- Edit bug report at https://bugs.php.net/bug.php?id=62914&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62914&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62914&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62914&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62914&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62914&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62914&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62914&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62914&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62914&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62914&r=support Expected behavior: https://bugs.php.net/fix.php?id=62914&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62914&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62914&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62914&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62914&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62914&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62914&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62914&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62914&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62914&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62914&r=mysqlcfg

« previous php.doc.bugs (#8758) next »