note 108311 added to function.class-uses
| From: | josh at bitmagnet dot org | Date: | Mon, 16 Apr 2012 19:46:54 +0000 |
| Subject: | note 108311 added to function.class-uses | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187188@lists.php.net to get a copy of this message | ||
I made a slight mistake in my last note, the correct code is below.
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( $t, $trait ))
return true;
unset( $traits[ $k ] );
}
}
return false;
}
?>
----
Server IP: 69.147.83.197
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/108311
Del: integrated -- https://master.php.net/note/delete/108311/integrated
Del: useless -- https://master.php.net/note/delete/108311/useless
Del: bad code -- https://master.php.net/note/delete/108311/bad+code
Del: spam -- https://master.php.net/note/delete/108311/spam
Del: non-english -- https://master.php.net/note/delete/108311/non-english
Del: in docs -- https://master.php.net/note/delete/108311/in+docs
Del: other reasons-- https://master.php.net/note/delete/108311
Reject -- https://master.php.net/note/reject/108311
Search -- https://master.php.net/manage/user-notes.php