Reputation:
I am new to php and learning it from php.net. As we know when we want to implement Traversable interface we implements IteratorAggregate or Iterator interface with user defined classes that implements the Traversable interface internally. But one thing that is confusing me in the 2nd note on that page (http://php.net/manual/en/class.traversable.php) which says:
When implementing an interface which extends Traversable, make sure to list IteratorAggregate or Iterator before its name in the implements clause.
Can anyone tell what does it says ?
Upvotes: 0
Views: 201
Reputation: 11250
Basically, when you create the class, after the implements statement, ensure you list IteratorAggregate or Iterator before the other interfaces in the declaration.
<?php
interface Spam extends \Traversable
{
// ...
}
final class Ham implements \IteratorAggregate, Spam
{
public function getIterator()
{
return new \ArrayIterator(range(1, 10));
}
}
Upvotes: 1