How to determine if a type implements an interface with PHP reflection?
Checking if an instance's class implements an interface?
interface IInterface
{
}
class TheClass implements IInterface
{
}
$cls = new TheClass();
if ($cls instanceof IInterface) {
echo "yes";
}
As therefromhere points out, you can use class_implements(). Just as with Reflection, this allows you to specify the class name as a string and doesn't require an instance of the class:
interface IInterface
{
}
class TheClass implements IInterface
{
}
$interfaces = class_implements('TheClass');
if (isset($interfaces['IInterface'])) {
echo "Yes!";
}