English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP basic tutorial

PHP advanced tutorial

PHP & MySQL

PHP reference manual

PHP get_declared_traits() function usage and example

PHP Class/Object function reference manual

The get_declared_traits() function returns an array of all defined traits

Syntax

get_declared_traits( void );

Definition and usage

Returns an array containing the names of all defined traits.

Parameter

Serial numberParameters and description
1

void

void indicates that no parameters are required.

Return value

 Returns an array containing the names of all defined traits. Returns NULL on failure.

Online example

The following is the usage of this function-

<?php
namespace  Example;
// Declare  Trait
trait  FooTrait
{
}
//Declare abstract class
abstract  class  FooAbstract
{
}
//Declare class
class  Bar  extends  FooAbstract
{
    use  FooTrait;
}
//Get all property declarations
$array  =  get_declared_traits();
var_dump($array);
?>
Test and see ‹/›

Output result:

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

PHP Class/Object function reference manual