PHP 快速導覽 - 核心延伸函數 類別、物件相關 trait_exists()

內建函數 (function) trait_exists() 判斷某個特徵類別 (trait) 是否存在

函數說明
bool trait_exists(string $traitname [, bool $autoload])$traitname 為特徵類別名稱。


參數 (parameter) 為特徵類別名稱,須注意回傳的是布林值。


舉例如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
trait Apple {};
 
if (trait_exists('Apple')) {
    echo "Apple existed.\n";
}
else {
    echo "Apple didn't exist.\n";
}
 
if (trait_exists('Spoon')) {
    echo "Spoon existed.\n";
}
else {
    echo "Spoon didn't exist.\n";
}
 
/* 《程式語言教學誌》的範例程式
    檔名:object17.php
    功能:示範 PHP 程式
    作者:張凱慶
    時間:西元 2013 年 2 月 */
?>


執行結果如下



中英文術語對照
函數function
陣列array
參數parameter


您可以繼續參考
類別、物件相關函數


相關目錄
回 PHP 快速導覽
回 PHP 教材
回首頁


參考資料
http://www.php.net/manual/en/function.trait-exists.php

沒有留言: