<?php
trait common{
function shout(){
return 'hello world!';
}
}
class a{
use common;
}
class b{
use common;
}
if(trait_exists('common')) {
echo (new a())->shout();
}
if(trait_exists('common')) {
echo (new b())->shout();
}
trait_exists
(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)
trait_exists — トレイトが存在するかどうかを調べる
説明
bool trait_exists
( string
$traitname
[, bool $autoload
] )
パラメータ
-
traitname -
調べたいトレイトの名前。
-
autoload -
まだロードされていない場合にオートロードするかどうか。
返り値
トレイトが存在する場合に TRUE、存在しない場合に FALSE、エラーが発生した場合に NULL を返します。
mr dot ryansilalahi at gmail dot com ¶
10 days ago
