Is it possible to get the methods of an implemented interface?
For example, to return only function bar() that is in interface.
interface iFoo
{
public function bar();
}
class Foo implements iFoo
{
public function bar()
{
...
}
public function fooBar()
{
...
}
}
I know I can use class_implements to return the implemented interfaces, for example
print_r(class_implements('Foo'));
output:
Array ( [iFoo] => iFoo )
How do I get the methods of the implemented interfaces?
By definition, implementing an interface means that you must define
ALL
methods in the child class, so what you are looking for isALL
of the methods from the interface(s).Single interface:
Outputs:
Multiple Interfaces:
Outputs:
Added interface
uFoo
to your example:You can use
Reflection
:Which outputs:
If you want to call the methods defined in
iFoo
ref on aFoo
object, you can do: