PHP get_declared_traits() Function
The PHP get_declared_traits() function returns an array with the name of all declared traits.
Syntax
get_declared_traits()
Parameters
No parameter is required.
Return Value
Returns an array of the names of the declared traits in the current script. Returns null in case of a failure.
Example: get_declared_traits() example
The example below shows the usage of get_declared_traits() function.
<?php namespace Example; //declaring trait trait FooTrait { } //declaring Abstract class abstract class FooAbstract { } //declaring class class Bar extends FooAbstract { use FooTrait; } //getting all declared traits print_r(get_declared_traits()); ?>
The output of the above code will be:
Array ( [0] => Example\FooTrait )
❮ PHP Classes/Objects Reference