略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: get_declared_traits

2024-05-06

get_declared_traits

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

get_declared_traits返回所有已定义的 traits 的数组

说明

get_declared_traits(): array

参数

此函数没有参数。

返回值

返回一个数组,其值包含了所有已定义的 traits 的名称。 在失败的情况下返回 null

参见

add a noteadd a note

User Contributed Notes 1 note

up
2
@everaldofilho
2 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"
* }
*/

官方地址:https://www.php.net/manual/en/function.get-declared-traits.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3