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

search for in the

iterator_apply> <class_parents
[edit] Last updated: Fri, 25 May 2012

view this page in

class_uses

(PHP 5 >= 5.4.0)

class_uses 指定したクラスが使っているトレイトを返す

説明

array class_uses ( mixed $class [, bool $autoload = true ] )

この関数は、指定したクラスが使っているトレイトの名前を配列で返します。 しかし、親クラスで使っているトレイトは含まれません。

パラメータ

class

オブジェクト (クラスのインスタンス) あるいは文字列 (クラス名)。

autoload

マジックメソッド __autoload() で、この関数からクラスを自動的に読み込ませるかどうか。

返り値

成功した場合に配列、エラー時には FALSE を返します。

例1 class_uses() の例

<?php

trait foo 
{ }
class 
bar {
  use 
foo;
}

print_r(class_uses(new bar));

print_r(class_uses('bar'));

function 
__autoload($class_name) {
   require_once 
$class_name '.php';
}

// __autoload で 'not_loaded' クラスを読み込みます
print_r(class_uses('not_loaded'true));

?>

上の例の出力は、 たとえば以下のようになります。

Array
(
    [foo] => foo
)

Array
(
    [foo] => foo
)

Array
(
    [trait_of_not_loaded] => trait_of_not_loaded
)

参考



add a note add a note User Contributed Notes class_uses
There are no user contributed notes for this page.

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