get_declared_traits

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

get_declared_traits宣言されているすべてのトレイトの配列を返す

説明

get_declared_traits(): array

パラメータ

この関数にはパラメータはありません。

戻り値

宣言されているすべてのトレイトの名前を値に持つ配列を返します。

参考

  • class_uses() - 指定したクラスが使っているトレイトを返す
  • trait_exists() - トレイトが存在するかどうかを調べる

add a note add a note

User Contributed Notes 1 note

up
2
@everaldofilho
4 years ago
Example of use:

<?php

namespace Example;

// Declare Trait
trait FooTrait
{
}

// Declare Abstract class
abstract class FooAbstract
{
}

// Declare class
class Bar extends FooAbstract
{
    use
FooTrait;
}

// Get all traits declareds
$array = get_declared_traits();

var_dump($array);
/**
* Result:

* array(1) {
*  [0] =>
*  string(23) "Example\FooTrait"
* }
*/
To Top