Bug #78799 [Opn->Nab]: Calling iterator_count() is killing the validity of RecursiveDirectoryIterator

From: Date: Sat, 09 Nov 2019 03:19:14 +0000
Subject: Bug #78799 [Opn->Nab]: Calling iterator_count() is killing the validity of RecursiveDirectoryIterator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223657@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78799&edit=1 ID: 78799 Updated by: requinix@php.net Reported by: k-gun at mail dot com Summary: Calling iterator_count() is killing the validity of RecursiveDirectoryIterator -Status: Open +Status: Not a bug Type: Bug Package: SPL related Operating System: Ubuntu PHP Version: 7.4.0RC4 Block user comment: N Private report: N New Comment: https://www.php.net/manual/en/function.iterator-count.php > iterator_count() is not guaranteed to retain the current position of the iterator. The only way to count how many items there are in an iterator is to run it to the end. Previous Comments: ------------------------------------------------------------------------ [2019-11-09 01:48:24] k-gun at mail dot com New email. ------------------------------------------------------------------------ [2019-11-09 01:46:22] k-gun at mail dot com Description: ------------ Hi, Calling iterator_count() is affecting RecursiveDirectoryIterator::valid() and RecursiveDirectoryIterator::valid() is returning false after iterator_count() call. I am not sure that is a bug or just a behavior of PHP, but simply looks weird invalidating it without any iteration act such as while or foreach. Test script: --------------- $iter = new RecursiveDirectoryIterator("/tmp/", RecursiveDirectoryIterator::SKIP_DOTS); var_dump($iter->valid()); var_dump(iterator_count($iter)); var_dump($iter->valid()); Expected result: ---------------- bool(true) int(24) bool(true) Actual result: -------------- bool(true) int(24) bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78799&edit=1

« previous php.bugs (#223657) next »