ConFoo Montreal 2026: Call for Papers

Voting

: max(five, three)?
(Example: nine)

The Note You're Voting On

ulf
12 years ago
A slighly modified version from Stealz that also checks all the "parent" traits used by the traits:

<?php
public static function class_uses_deep($class, $autoload = true)
{
$traits = [];

// Get traits of all parent classes
do {
$traits = array_merge(class_uses($class, $autoload), $traits);
} while (
$class = get_parent_class($class));

// Get traits of all parent traits
$traitsToSearch = $traits;
while (!empty(
$traitsToSearch)) {
$newTraits = class_uses(array_pop($traitsToSearch), $autoload);
$traits = array_merge($newTraits, $traits);
$traitsToSearch = array_merge($newTraits, $traitsToSearch);
};

foreach (
$traits as $trait => $same) {
$traits = array_merge(class_uses($trait, $autoload), $traits);
}

return
array_unique($traits);
}
?>

<< Back to user notes page

To Top