PHP Conference Nagoya 2025

ReflectionClass::implementsInterface

(PHP 5, PHP 7, PHP 8)

ReflectionClass::implementsInterfaceArayüz gerçeklenmiş mi diye bakar

Açıklama

public ReflectionClass::implementsInterface(ReflectionClass|string $interface): bool

Belirtilen arayüzü gerçeklenmişse true döner.

Bağımsız Değişkenler

arayüz

Bakılacak arayüzün ismi.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner.

Hatalar/İstisnalar

arayüz bir arayüz değilse bir ReflectionException yavrulanır.

Ayrıca Bakınız

add a note

User Contributed Notes 3 notes

up
2
jtunaley at gmail dot com
6 years ago
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)
?>
up
1
dhairya dot coder at gmail dot com
8 years ago
//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
up
0
keepchen2016 at gmail dot com
7 years ago
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
To Top