Determine which interfaces a class explicitly implements, excluding inheritance

Viewed 63

I'm working on a GUI which introspects its working environment to provide a visual representation of class hierarchy.

I need to get the list of interfaces that a class explicitly implements, excluding the inherited ones, much like class_uses(). Both class_implements() and ReflectionClass::getInterfaceNames() seem to return all interfaces implemented in the hierarchy.

Example:

interface A {}
interface B {}
interface C {}
interface D extends C {}
class M implements A,B {}
class N extends M implements B,D {}

// For N I need some getOwnInterfaces('N') function to return ['B','D']
// class_implements('N') returns ['A','B','C','D']

Note in the example above, interface B is declared as implemented both at the super class and on the specialized class. I actually have practical occurences of this in the code.

1 Answers

You can get a list of implemented interfaces, then for each one check if it is also implemented by the base class (several methods available to do that).

Interfaces that are not implemented by the base class are those implemented directly.

Related