如何在 PHP 中查看特征的方法名称

tab*_*itu 1 php traits

是否有类似于 get_class_methods() 的 PHP 函数适用于特征?我有兴趣查看特征上的所有方法/函数。

tab*_*itu 8

简短的回答 - 没有 PHP 函数,但你可以使用 ReflectionClass 来做到这一点:

$reflection = new ReflectionClass('App\YourTrait');
$traitMethods = $reflection->getMethods();
Run Code Online (Sandbox Code Playgroud)

关于此的 PHP 文档: http://php.net/manual/ro/class.reflectionclass.php

希望它可以节省某人的时间。我确实浪费了太多时间来发现这一点。