tabacitu
tabacitu

Reputation: 6193

How to see a trait's method names in PHP

Is there a PHP function similar to get_class_methods() that works for traits? I'm interested in seeing all methods/functions on a trait.

Upvotes: 1

Views: 966

Answers (1)

tabacitu
tabacitu

Reputation: 6193

Short answer - there's no PHP function, but you can do it using ReflectionClass:

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

PHP Documentation about this: http://php.net/manual/ro/class.reflectionclass.php

Hope it saves someone time. I sure wasted too much on finding this out.

Upvotes: 8

Related Questions