note 119551 added to globiterator.count
| From: | TwystO | Date: | Tue, 05 Jul 2016 10:49:44 +0000 |
| Subject: | note 119551 added to globiterator.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205879@lists.php.net to get a copy of this message | ||
As stated here https://bugs.php.net/bug.php?id=55701 the count()
method can lead to errors.
For example this won't works if no files are found in the target directory :
<?php
$iterator = new \GlobIterator($ftpDirectory . '/*.*',
FilesystemIterator::KEY_AS_FILENAME);
if($iterator->count()) {
foreach($iterator as $filePath) {
// do some stuff ...
}
}
?>
A workaround to this bug could be :
<?php
foreach(new \GlobIterator($ftpDirectory . '/*.*', FilesystemIterator::KEY_AS_FILENAME) as
$filePath) {
// do some stuff ...
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 90.105.121.123
----
Manual Page -- http://php.net/manual/en/globiterator.count.php
Edit -- https://master.php.net/note/edit/119551
Del: integrated -- https://master.php.net/note/delete/119551/integrated
Del: useless -- https://master.php.net/note/delete/119551/useless
Del: bad code -- https://master.php.net/note/delete/119551/bad+code
Del: spam -- https://master.php.net/note/delete/119551/spam
Del: non-english -- https://master.php.net/note/delete/119551/non-english
Del: in docs -- https://master.php.net/note/delete/119551/in+docs
Del: other reasons-- https://master.php.net/note/delete/119551
Reject -- https://master.php.net/note/reject/119551
Search -- https://master.php.net/manage/user-notes.php