tags:

views:

106

answers:

2
+1  Q: 

PHP Interfaces

I have defined an interface for a data structure type. I am trying to force whatever class implementing that interface to also implement two other interfaces (iterator and countable).

Is there a way to do this?

A: 

Have your interface implement them and then just pass on the abstract methods (i.e. don't implement the methods in your interface)

Malfist
+2  A: 

If you want to force it, you could declare that your interface extends the interfaces you required, e.g.

interface c extends a, b
{
   ...
}

Generally speaking though, you should probably be writing code which checks that an object has all the interfaces required for a particular operation before carrying it out. Makes things easier to maintain and extend in the long run...

Paul Dixon
Oh nice, thanks! I was trying interface abc implements countable {}, giving a syntax error.
Mario