The spl has some really cool features but some odd naming conventions and some real GOTCHAs. This library is intended to make the spl code easier to use

v0.2.0 2014-02-25 11:00 UTC


Build Status Latest Stable Version License

The php spl has some really cool feaures but also some bugs/gotchas. This is a library to wrap and hopefully reduce the pain caused by the spl.


The easiest way to install this library is using composer. In your project's composer.json file add:

        "require": {
            "mead-steve/spl-fix": "dev-master"

Then run composer update.



The limit iterator is very useful if you want to grab a subset of an iterator. Good right? Pass it to count() however and you'll always get a value of 1. This package provides an updated LimitIterator class that correctly implements countable.


Fixed so that passing it to count() returns zero. It's empty after all.


The spl FilterIterator can only be passed an iterator. This is now wrapped so that any traversable can be passed in. This is handled by wrapping the traversable in an IteratorIterator. The following child Iterators have also been wrapped:

  • RegexIterator



This is a short hand for wrapping an array in a RecursiveIterator then wrapping that in a RecursiveIteratorIterator.


The IteratorWalker allows iterators to be used in the same way arrays are used in array_walk. So that the two snippets will behave in the same way:

    array_walk($array, function($value, $key) {
        echo $key . "=>" . $value;
    $walker = new IteratorWalker($iterator);
    $walker->walk(function($value, $key) {
        echo $key . "=>" . $value;