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 ...
}
?>
PHP.mk документација
GlobIterator::count
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
globiterator.count.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
globiterator.count.php
GlobIterator::count
Референца за `globiterator.count.php` со подобрена типографија и навигација.
GlobIterator::count
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
GlobIterator::count — Get the number of directories and files
= NULL
Gets the number of directories and files found by the glob expression.
Параметри
Оваа функција нема параметри.
Вратени вредности
The number of returned directories and files, as an int.
Примери
Пример #1 FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO example
<?php
$iterator = new GlobIterator('*.xml');
printf("Matched %d item(s)\r\n", $iterator->count());
?>Горниот пример ќе прикаже нешто слично на:
Matched 8 item(s)
Види Исто така
- GlobIterator::__construct() - Земи го бројот на директориуми и датотеки
- count() - Брои сите елементи во список или во Countable објект
- glob() - Најди имиња на патеки што одговараат на шема
Белешки од корисници 1 белешка
TwystO ¶
пред 9 години