(PHP 5 >= 5.1.0)
class_implements — 返回指定的類實(shí)現(xiàn)的所有接口。
說明
array class_implements ( mixed$class
[, bool $autoload
] )
本函數(shù)返回一個(gè)數(shù)組,該數(shù)組中包含了指定類class
及其父類所實(shí)現(xiàn)的所有接口的名稱。
參數(shù)
class
對象(類實(shí)例)或字符串(類名稱)。
autoload
是否允許使用__autoload
魔術(shù)函數(shù)來自動裝載該類。默認(rèn)值為TRUE
。
返回值
調(diào)用成功則返回一個(gè)數(shù)組,否則返回FALSE
。
更新日志
版本
說明
5.1.0
增加了允許參數(shù)class
為字符串的選項(xiàng)。增加了autoload
參數(shù)。
范例
Example #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));
?>
以上例程的輸出類似于:
Array ( [foo] => foo ) Array ( [interface_of_not_loaded] => interface_of_not_loaded )
參見
class_parents() - 返回指定類的父類。 get_declared_interfaces() - 返回一個(gè)數(shù)組包含所有已聲明的接口