downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Classkit> <property_exists
[edit] Last updated: Fri, 24 May 2013

view this page in

trait_exists

(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)

trait_existsトレイトが存在するかどうかを調べる

説明

bool trait_exists ( string $traitname [, bool $autoload ] )

パラメータ

traitname

調べたいトレイトの名前。

autoload

まだロードされていない場合にオートロードするかどうか。

返り値

トレイトが存在する場合に TRUE、存在しない場合に FALSE、エラーが発生した場合に NULL を返します。



add a note add a note User Contributed Notes trait_exists - [1 notes]
up
0
mr dot ryansilalahi at gmail dot com
10 days ago
<?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();
}

 
show source | credits | stats | sitemap | contact | advertising | mirror sites