What is "spliterator"

Iterator and SPL: Classes as array.

Very interesting part of PHP is SPL. The Standart PHP Library came to meet various needs of useful classes and interfaces to any system, such as Array Classes, iterators, file system iterators and many others. And what is the real use of this? Several.

Now, you can have a standard way to list directories, with no functions that look more like scams. It also brings better features for recursive iterators, for example. And the title?

As part of SPL, they have two classes that I have used in particular: Arrayaccess and Iterator.

Iterator is an interface that allows you to transition(walk, advance, move) into a basic form object, as if it were an array. Normally do for example foreach($obj as $property=>$value), you would navigate through the defined attributes of the class. In the case of iterator, it is an object that knows how to do this, in a custom way. For example, you can define an Iterator that instead of moving forward through the methods of the past object, navigate through only specific elements, or in a property that has a list. Anyway, just use creativity.

Arrayaccess is also very special, this interface allows access to your object as if it were an array even with "$obj[1]" or even "$obj[]".

There are others too, that in another opportunity I will speak, but these I am in greater contact and advise to all who use PHP to pay some homage to SPL, who knows not make your life a little easier.

That being said, I have a Class, somewhat Energy, called Collection. It, as the name says, is a class to deal with lists, vectors and etc... It implements these two interfaces, so it is able to behave with all the features of an array, plus the advantages of an Object.

On the class page have the example file, where you can see some of its uses. I personally use in something like this:

<?
class PageList extends Collection {
  function __construct() {
    $pageDAO = new PageDAO ;
    $pages = $pageDAO->select();
    $this->merge($pages);
  }
}
?>

That is, I can in my code use only $pages = new Pagelist, and I will already have a fully manipulable, iterable object and do things like foreach($pages as $page) or while($page = $pages->fetch()) naturally and without gambiarras.

I can still overwrite the methods add() and set() to have greater control over the collection... again are many possibilities.

In addition, of course, to being useful for studying