【问题标题】:How to see a trait's method names in PHP如何在 PHP 中查看 trait 的方法名称
【发布时间】:2016-05-25 22:44:57
【问题描述】:

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

【问题讨论】:

    标签: php traits


    【解决方案1】:

    简短的回答 - 没有 PHP 函数,但您可以使用 ReflectionClass 来完成:

    $reflection = new ReflectionClass('App\YourTrait');
    $traitMethods = $reflection->getMethods();
    

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

    希望它能节省一些人的时间。我确实在发现这一点上浪费了太多时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2022-10-06
      • 2011-10-13
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多