Starting with PHP5 almost any PHP installation contained SPL (Standard PHP Library) extension – with few exceptions, when hosters intentionally disabled it. With PHP 5.3 out, this extension is considered to be within PHP core, and as such it’s not possible to disable it anymore. This in fact is a good thing, as SPL really deserves to be the core component.
In an attempt to shed some light on and to draw attention to SPL, I plan to post several articles discussing various parts of this extension. I will start with SPL Interfaces so that you can grasp immediately the usefulness of the SPL.
Comprehending SPL interfaces presupposes that you know standard interfaces that come build-in with PHP5. So, I wrote preliminary article discussing them – I consider it to be a prerequisite for good understanding of the current material.
Covered in this article:
Read the rest of this entry
Interfaces, PHP5, SPL
Note: This article serves as preliminary for SPL Interfaces article to be published later on.
I wanted to provide good overview of (highly under-used) Standard PHP Library (SPL) starting with interfaces. However, without firstly discussing predefined interfaces, which come bundled with each and every PHP distribution, discussion of SPL-provided ones seemed to be incomplete.
To be covered in this article:
Read the rest of this entry
OO, PHP5, SPL
Вопрос: Как, используя PHP5, показать содержимое определенного каталога?
Рецепт:
Легко! Используйте итераторы (в данном случае DirectoryIterator):
1
2
3
| foreach (new DirectoryIterator('./') as $Item) {
echo $Item->current();
} |
Для просмотра доступных методов DirectoryIterator – смотрите в мануал.
N.B. Итератор DirectoryIterator возвращает объект собственного типа, т.е. $Item является объектом класса DirectoryIterator.
php iterators, SPL, Tips