Example 1 - Echo all classes implementing the w3coded interface certain Iterator Interface,Example 2 - Return array of w3coded interface certain all classes implementing the Iterator w3coded interface certain Interface,You can use PHP's w3coded interface certain ReflectionClass::implementsInterface and w3coded interface certain get_declared_classes functions to accomplish w3coded interface certain this:,class_implements — Return the interfaces w3coded interface certain which are implemented by the given class
Usage
in_array('InterfaceName', class_implements('className'));
Example 1 - Echo all classes implementing the Iterator Interface
foreach (get_declared_classes() as $className) {
if (in_array('Iterator', class_implements($className))) {
echo $className, PHP_EOL;
}
}
Example 2 - Return array of all classes implementing the Iterator Interface
print_r(
array_filter(
get_declared_classes(),
function ($className) {
return in_array('Iterator', class_implements($className));
}
)
);
You can use PHP's ReflectionClass::implementsInterface
and get_declared_classes
functions to accomplish this:
$classes = get_declared_classes();
$implementsIModule = array();
foreach($classes as $klass) {
$reflect = new ReflectionClass($klass);
if($reflect->implementsInterface('IModule'))
$implementsIModule[] = $klass;
}
Generic solution:
function getImplementingClasses( $interfaceName ) {
return array_filter(
get_declared_classes(),
function( $className ) use ( $interfaceName ) {
return in_array( $interfaceName, class_implements( $className ) );
}
);
}
Last Update : 2023-09-22 UTC 13:29:03 PM
Last Update : 2023-09-22 UTC 13:28:51 PM
Last Update : 2023-09-22 UTC 13:28:35 PM
Last Update : 2023-09-22 UTC 13:28:15 PM
Last Update : 2023-09-22 UTC 13:27:59 PM
Last Update : 2023-09-22 UTC 13:27:37 PM
Last Update : 2023-09-22 UTC 13:27:17 PM