0

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 ?

1 Answers1

1

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));
    }
}
Steven Scott
  • 10,234
  • 9
  • 69
  • 117
  • What is the **spam** here ? –  Sep 29 '17 at 22:33
  • Does **spam** means => (**IteratorAggregate** or **Iterator**) interfaces? –  Sep 29 '17 at 22:35
  • Sorry i didn't get you. What you mean **When you create a class after implementings statement**, what does that means ? –  Sep 29 '17 at 22:37
  • Just an interface. Spam as in canned meat, then Ham is the other class. This is from online help files. Spam is an interface that is Traversable and would have some functionality. Ham is than a class that has additional functionality. – Steven Scott Sep 30 '17 at 01:07