(PHP 5, PHP 7, PHP 8)
class_implements — 返回指定的類(lèi)實(shí)現的所有接口。
本函數返回一個(gè)數組,該數組中包含了指定類(lèi)class
及其父類(lèi)所實(shí)現的所有接口的名稱(chēng)。
class
對象(類(lèi)實(shí)例)或字符串(類(lèi)名稱(chēng))。
autoload
是否允許使用__autoload
魔術(shù)函數來(lái)自動(dòng)裝載該類(lèi)。默認值為true
。
調用成功則返回一個(gè)數組,否則返回false
。
版本 | 說(shuō)明 |
---|---|
5.1.0 |
增加了允許參數class 為字符串的選項。增加了autoload 參數。
|
示例 #1 class_implements() example
<?php
interface foo { }
class bar implements foo {}
print_r(class_implements(new bar));
// since PHP 5.1.0 you may also specify the parameter as a string
print_r(class_implements('bar'));
function __autoload($class_name) {
require_once $class_name . '.php';
}
// use __autoload to load the 'not_loaded' class
print_r(class_implements('not_loaded', true));
?>
以上例程的輸出類(lèi)似于:
Array ( [foo] => foo ) Array ( [interface_of_not_loaded] => interface_of_not_loaded )