interface_exists()function 是一個內置函數PHP檢查接口是否已定義。
用法:
bool interface_exists(string $interface, bool $autoload = true)
參數:該函數接受兩個參數,如下所述:
- $interface:該參數保存接口名稱。
- $autoload:該參數默認檢查是否調用自動加載。
返回值:如果給定的接口已定義,則返回“true”,否則返回“false”。
示例 1:在此示例中,我們將使用以下命令檢查接口是否已定義interface_exists()函數。
PHP
<?php
if (interface_exists('MyInterface')) {
class MyClass implements MyInterface {
}
echo "A class using 'Interface' is created.";
} else {
echo "'Interface' do not exist!.";
}
?>
輸出:
'Interface' does not exist!
示例 2:在下麵的代碼示例中,我們將定義一個接口,然後使用interface_exists()函數。
PHP
<?php
interface MyInterface{
public function hello() ;
}
if (interface_exists('MyInterface')) {
class MyClass implements MyInterface {
function hello(){
echo "Hey GeeksforGeeks";
}
}
echo "A class using 'Interface' is created.\n";
} else {
echo "'Interface' does not exist!.";
}
$MyInterface = new MyClass() ;
$MyInterface->hello() ;
?>
輸出:
A class using 'Interface' is created. Hey GeeksforGeeks
參考:https://www.php.net/manual/en/function.interface-exists.php
相關用法
- PHP interface_exists()用法及代碼示例
- PHP intdiv()用法及代碼示例
- PHP intl_is_failure()用法及代碼示例
- PHP intval()用法及代碼示例
- PHP in_array()用法及代碼示例
- PHP inet_ntop()用法及代碼示例
- PHP inet_pton()用法及代碼示例
- PHP include_once()、require_once()用法及代碼示例
- PHP include()和include_once()的區別用法及代碼示例
- PHP is_finite()用法及代碼示例
- PHP is_infinite()用法及代碼示例
- PHP is_nan()用法及代碼示例
- PHP is_file()用法及代碼示例
- PHP is_uploaded_file()用法及代碼示例
- PHP is_subclass_of()用法及代碼示例
- PHP imap_8bit()用法及代碼示例
- PHP imap_alerts()用法及代碼示例
- PHP imap_append()用法及代碼示例
- PHP imap_base64()用法及代碼示例
- PHP imap_binary()用法及代碼示例
- PHP imap_body()用法及代碼示例
- PHP imap_bodystruct()用法及代碼示例
- PHP imap_check()用法及代碼示例
- PHP imap_clearflag_full()用法及代碼示例
- PHP imap_close()用法及代碼示例
注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP interface_exists() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。