Sven
Sven

Reputation: 13296

Zend Framework 2: What is a Traversable object?

I am just getting into Zend Framework 2. In various parts of the documentation, they talk about "Traversable objects". What do they mean with that?

So far, the all of the configurations I encountered while using the framework have been realized using (often nested associative) arrays.

Upvotes: 0

Views: 455

Answers (1)

Marcin Twardowski
Marcin Twardowski

Reputation: 574

Traversable object is one that implements Iterator or IteratorAggregate interface. That object can be used in foreach loop. You can read about Traversable interface here: http://php.net/manual/en/class.traversable.php#class.traversable .

This is abstract interface so you cannot implement own Traversable interface but you can determine if object is Traversable (implement Iterator or IteratorAggregate interface) by checking object instanceof Traversable

.

Upvotes: 2

Related Questions