interface_exists() 函數(shù)檢查接口是否已被定義
interface_exists ( $interface_name [, $autoload] );
此函數(shù)檢查是否已定義給定接口。
| 序號 | 參數(shù)及說明 |
|---|---|
| 1 | interface_name(必需) 接口名稱 |
| 2 | autoload(可選) 默認是否調(diào)用 __autoload。 |
本函數(shù)在由 interface_name 給出的接口已定義時返回 TRUE,否則返回 FALSE。
以下是此函數(shù)的用法-
<?php
// 在嘗試使用前先檢查接口是否存在
if (interface_exists('SomeInterface')) {
class MyClass implements SomeInterface {
// 方法
}
}
?>