ReflectionClass::implementsInterface()函數是PHP中的內置函數,用於檢查指定的接口是否存在。
用法:
bool ReflectionClass::implementsInterface( string $interface )
參數:該函數接受單個參數$interface,該參數保存正在檢查的指定接口。
返回值:成功時此函數返回true,失敗時返回false。
以下示例程序旨在說明PHP中的ReflectionClass::implementsInterface()函數:
程序1:
<?php
// Defining some interfaces
interface Colleges { }
interface Departments { }
interface Students { }
interface Companies { }
// Initialising a class of Interfaces
class Interfaces implements Colleges,
Departments, Students, Companies { }
// Using ReflectionClass over the class Interfaces
$A = new ReflectionClass("Interfaces");
// Calling the implementsInterface() function
// over the Interface 'Colleges'
$B = $A->implementsInterface('Colleges');
// Getting the value true or false
var_dump($B);
?>
輸出:
bool(true)
程序2:
<?php
// Defining a SuperClass interface Company
interface Company {
public function GFG();
}
// Defining a different interface Company1
interface Company1 {
public function GeeksforGeeks();
}
// Defining a subclass Departments
class Departments implements Company {
public function GFG() {}
}
// Using ReflectionClass() over the
// subclass Departments
$reflect = new ReflectionClass('Departments');
// Calling implementsInterface() function
$A = $reflect->implementsInterface('Company1');
// Getting the value either true or false
var_dump($A);
?>
輸出:
bool(false)
參考: https://www.php.net/manual/en/reflectionclass.implementsinterface.php
相關用法
- PHP ReflectionClass getTraits()用法及代碼示例
- PHP ReflectionClass getReflectionConstant()用法及代碼示例
- PHP ReflectionClass isFinal()用法及代碼示例
- PHP ReflectionClass getTraitNames()用法及代碼示例
- PHP ReflectionClass getInterfaces()用法及代碼示例
- PHP ReflectionClass isInstance()用法及代碼示例
- PHP ReflectionClass getTraitAliases()用法及代碼示例
- PHP ReflectionClass hasMethod()用法及代碼示例
- PHP ReflectionClass getExtensionName()用法及代碼示例
- PHP ReflectionClass getProperties()用法及代碼示例
- PHP ReflectionClass getProperty()用法及代碼示例
- PHP ReflectionClass getStaticProperties()用法及代碼示例
- PHP ReflectionClass __toString()用法及代碼示例
- PHP ReflectionClass getFileName()用法及代碼示例
- PHP ReflectionClass getDefaultProperties()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionClass implementsInterface() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。