phpoopinterfaceimplements

How many interfaces can a class implement in PHP?


I'm looking for an answer to question which is not difficult, but I can't find out how many interfaces can be implemented by one class.

Is this possible?

class Class1 implements Interface1, Interface2, Interface3, Interface4 {
   .....
}

For all the similar examples I found, I've seen that there can be only 2 interfaces implemented by one class. But there isn't any info about what I'm looking for.


Solution

  • There is no limit on the number of interfaces that you can implement. By definition, you can only extend (inherit) one class.

    I would, as a practical matter, limit the number of Interfaces you do implement, lest your class become overly bulky and thus hard to work with.