PHP Traversable interface


Traversable is an abstract interface, hence it can not be directly implemented by any class. Generally, Iterator or IteratorAggregate interfaces, which extend Traversable, are used to check if implementing class is traversable using foreach construct in PHP.

Certain built-in classes that implement this interface can be used in foreach and need not implement iterator interfaces. Since Traversable is an abstract interface, it doesn't have any methods in it.


Traversable {

When implementing IteratorAggregate or Iterator interface which extends Traversable, they must be listed before its name in the implements clause.

Updated on: 21-Sep-2020


Kickstart Your Career

Get certified by completing the course

Get Started