PHPackages                             wmde/traversable-iterator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wmde/traversable-iterator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wmde/traversable-iterator
=========================

Turn Traversable objects into Iterators. Fixed version of the native IteratorIterator

1.0.0(9y ago)016.8k1GPL-2.0+PHPPHP &gt;=7.0

Since Jun 17Pushed 7y ago8 watchersCompare

[ Source](https://github.com/wmde/traversable-iterator)[ Packagist](https://packagist.org/packages/wmde/traversable-iterator)[ Docs](https://github.com/wmde/traversable-iterator)[ RSS](/packages/wmde-traversable-iterator/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (2)Used By (1)

Traversable Iterator
====================

[](#traversable-iterator)

[![Build Status](https://camo.githubusercontent.com/f9902bbbd11f97b83735435f85a598a9cf9acc582a0e2a0352d984c01d103179/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f776d64652f7472617665727361626c652d6974657261746f722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/wmde/traversable-iterator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d516a327686b029d2381a7a1cacd330534b9b8c1fcb0d2a5e8aeb6330c486ceb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f7472617665727361626c652d6974657261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/wmde/traversable-iterator/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/78fdf614b6b2376dd39df6e3d53d789945d62ebbf95b3d14aacf4b94543e0fdd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f776d64652f7472617665727361626c652d6974657261746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/wmde/traversable-iterator/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/89e9fa61236ad282f835d3d0c02c54a3cf0f038140b658f5a347bad4d009fd1d/68747470733a2f2f706f7365722e707567782e6f72672f776d64652f7472617665727361626c652d6974657261746f722f76657273696f6e2e706e67)](https://packagist.org/packages/wmde/traversable-iterator)[![Download count](https://camo.githubusercontent.com/39fddf667d796286a7aca0b588e4c8dab7e5525fea863a083a4297c56d47223f/68747470733a2f2f706f7365722e707567782e6f72672f776d64652f7472617665727361626c652d6974657261746f722f642f746f74616c2e706e67)](https://packagist.org/packages/wmde/traversable-iterator)

`Iterator` that can be constructed from `Traversable` objects.

Can be seen as a fixed version of `IteratorIterator` (which is used internally). `IteratorIterator`behaves in unexpected ways when constructed from an `IteratorAggregate`: it only calls `getIterator`once rather than once per iteration, which is what happens when you traverse the `IteratorAggregate`directly. In other words: looping over an `IteratorIterator` that contains a `IteratorAggregate` yields different behaviour than looping over the `IteratorAggregate` itself. This is unexpected and can be problematic. For instance when the `IteratorAggregate` contains a `Generator` (which happens often), looping over the `IteratorIterator` more than once will cause an error due to the `Generator` not being rewindable.

Example of how `IteratorIterator` fails:

```
$iteratorAggregate = new class() implements \IteratorAggregate {
	public function getIterator() {
		yield 'a';
		yield 'b';
		yield 'c';
	}
}

$iterator = new IteratorIterator( $iteratorAggregate );

foreach ( $iterator as $value ) {}
foreach ( $iterator as $value ) {} // Exception: Cannot rewind a generator that was already run
```

This exception, and more generally difference in behaviour, does not occur when using `TraversableIterator`.

Installation
------------

[](#installation)

To add this package as a local, per-project dependency to your project, simply add a dependency on `wmde/traversable-iterator` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Traversable Iterator 1.x:

```
{
    "require": {
        "wmde/traversable-iterator": "~1.0"
    }
}
```

Usage
-----

[](#usage)

Running the tests
-----------------

[](#running-the-tests)

For a full CI run

```
composer ci

```

For tests only

```
composer test

```

For style checks only

```
composer cs

```

Release notes
-------------

[](#release-notes)

### 1.0.0 (2017-06-17)

[](#100-2017-06-17)

- Initial release

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3303d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (10 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/wmde-traversable-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/wmde-traversable-iterator/health.svg)](https://phpackages.com/packages/wmde-traversable-iterator)
```

###  Alternatives

[soup/paginator

Paginator is a simple class that allows you to create pagination. It doesn't require any database connection. It is compatible with Twitter's Bootstrap Framework, by using the CSS class pagination that is also attached.

351.6k](/packages/soup-paginator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
