how to get used traits in php-class?

2019-04-03 11:51发布

Is there any function in PHP (5.4) to get used traits as array or similar:

class myClass extends movingThings {
  use bikes, tanks;

  __construct() {
    echo 'I\'m using the two traits:' . ????; // bikes, tanks
  }
}

标签: php oop traits
7条回答
Viruses.
2楼-- · 2019-04-03 12:52

Short answer: you shouldn't. Traits are almost exactly copy and paste code. You don't NEED to know which traits are used, only on what the traits generate.

Answer I don't want to give: use ReflectionClass::getTraits. I'm not going to elaborate on this one.

查看更多
登录 后发表回答