note 108306 deleted from function.class-uses by danbrown

From: Date: Thu, 10 May 2012 17:10:59 +0000
Subject: note 108306 deleted from function.class-uses by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187666@lists.php.net to get a copy of this message
Note Submitter: josh at bitmagnet dot org ---- 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; } ?>

« previous php.notes (#187666) next »