note 108306 added to function.class-uses
| From: | josh at bitmagnet dot org | Date: | Mon, 16 Apr 2012 04:45:38 +0000 |
| Subject: | note 108306 added to function.class-uses | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187156@lists.php.net to get a copy of this message | ||
Since traits can use other traits, the following function will recursively check if a class uses a
trait anywhere in the trait hierarchy.
<?php
function class_uses_recursive( $class, $trait )
{
$traits = class_uses( $class );
while( !empty( $traits ))
{
foreach( $traits as $k => $t )
{
if( $t === $trait )
return true;
if( class_uses_recursive( $class, $t ))
return true;
unset( $traits[ $k ] );
}
}
return false;
}
?>
----
Server IP: 208.69.120.55
Probable Submitter: 96.238.181.89
----
Manual Page -- http://www.php.net/manual/en/function.class-uses.php
Edit -- https://master.php.net/note/edit/108306
Del: integrated -- https://master.php.net/note/delete/108306/integrated
Del: useless -- https://master.php.net/note/delete/108306/useless
Del: bad code -- https://master.php.net/note/delete/108306/bad+code
Del: spam -- https://master.php.net/note/delete/108306/spam
Del: non-english -- https://master.php.net/note/delete/108306/non-english
Del: in docs -- https://master.php.net/note/delete/108306/in+docs
Del: other reasons-- https://master.php.net/note/delete/108306
Reject -- https://master.php.net/note/reject/108306
Search -- https://master.php.net/manage/user-notes.php