Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Get Names Of Aliased Traits

Tags:

php

I have a few aliased traits in PHP like so:

class Foo {
    use Bar, Other {
        Bar as One;
        Bar as Two;
        Other as Three;
    }
}

Is there a way to get a list of the currently used traits and their aliased names for that class? I know PHP has class_uses(), but that only returns Bar and Other not One, Two or Three in the example above. I'd like to have a key => value of the Original name and the aliased name. Anyone happen to know how? I've done a lot of googling with no results.

like image 782
Bravo Delta Avatar asked Jan 18 '26 11:01

Bravo Delta


1 Answers

Looks like you can use ReflectionClass to get this. Specifically the getTraitAliases method:

http://php.net/manual/en/reflectionclass.gettraitaliases.php

like image 99
jszobody Avatar answered Jan 21 '26 05:01

jszobody