Skip to content

Instantly share code, notes, and snippets.

@simodima
Created June 25, 2016 15:28
Show Gist options
  • Save simodima/8653b83afc963a4a67d0e824e66fe10f to your computer and use it in GitHub Desktop.
Save simodima/8653b83afc963a4a67d0e824e66fe10f to your computer and use it in GitHub Desktop.
PHP iterable interfaces
<?php
interface Iterator extends Traversable
{
abstract public mixed current ( void )
abstract public scalar key ( void )
abstract public void next ( void )
abstract public void rewind ( void )
abstract public boolean valid ( void )
}
<?php
interface IteratorAggregate extends Traversable
{
abstract public Traversable getIterator( void )
}
<?php
/**
* Interface to detect if a class is traversable using foreach.
* Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator.
*/
abstract interface Traversable
{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment