ReflectionClass::implementsInterface

(PHP 5)

ReflectionClass::implementsInterfaceImplements interface

Description

public bool ReflectionClass::implementsInterface ( string $interface )

Checks whether it implements an interface.

Parameters

interface

The interface name.

Return Values

Returns TRUE on success or FALSE on failure.

See Also

Коментарии

//checks that whether class Fruit implements interface apple or not 

interface Apple {
   
    function taste();
}

class Fruit implements Apple {
   
    function taste() {
        echo "Seet";
    }
}

$obj=new ReflectionClass('Fruit');
var_dump($obj->implementsInterface('Apple'));  //Here it will checks that whether class Fruit implements interface apple or not
2016-02-11 05:48:07
http://php5.kiev.ua/manual/ru/reflectionclass.implementsinterface.html
interface Factory
{
    public function sayHello();
}

class ParentClass implements Factory
{
    public function sayHello()
    {
        echo "hello\n";
    }
}

class ChildrenClass extends ParentClass
{

}

$reflect = new ReflectionClass('ParentClass');
var_dump($reflect->implementsInterface('Factory'));

$second_ref = new ReflectionClass('ChildrenClass');
var_dump($second_ref->isSubclassOf('ParentClass'));

$third_ref = new ReflectionClass('Factory');
var_dump($third_ref->isInterface());

//can not be called as static
var_dump(ReflectionClass::isInterface('Factory'));
die;
//#result
bool(true)
bool(true)
bool(true)
PHP Fatal error:  Non-static method ReflectionClass::isInterface() cannot be called statically
2017-06-02 11:49:45
http://php5.kiev.ua/manual/ru/reflectionclass.implementsinterface.html
Note that this method also returns true when the thing you're reflecting is the interface you're checking for:

<?php
interface MyInterface {}

$reflect = new ReflectionClass('MyInterface');
var_dump($reflect->implementsInterface('MyInterface')); // bool(true)
?>
2018-06-07 01:22:29
http://php5.kiev.ua/manual/ru/reflectionclass.implementsinterface.html

    Поддержать сайт на родительском проекте КГБ