org_heigl / trait-iterator
A Trait for the iterator-interface
1.2.1
2026-11-14 18:58 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-30 03:15:25 UTC
README
Often used implementation of the IteratorInterface
Installation
composer require org_heigl/trait-iterator
Usage
Add it to a class like this:
use Org_Heigl\IteratorTrait\IteratorTrait; class MyList implements \Iterator { use IteratorTrait; /** * Can be an array or an Object implementing traversable * * @var array<Object> */ protected $yourArrayToIterateOver = []; public function & getIterableElement() { return $yourArrayToIterateOver } public function current(): Object { return current($this->getIterableElement()); } }
The rest of the Iterator implementation is handled within the IteratorTrait.
Issues
Feel free to drop an issue on github when you need help.