Reputation: 27982
I'm looping through an array of class names in PHP, fetched via get_declared_classes().
How can I check each class name to detect whether or not that particular class is an abstract class or not?
Upvotes: 22
Views: 6889
Reputation: 134631
Use reflection. ReflectionClass
->isAbstract()
Use it like this:
$class = new ReflectionClass('NameOfTheClass');
$abstract = $class->isAbstract();
Upvotes: 46
Reputation: 33388
<?php
abstract class Picasso
{
public function __construct()
{
}
}
$class = new ReflectionClass('Picasso');
if($class->isAbstract())
{
echo "Im abstract";
}
else
{
echo "Im not abstract";
}
?>
See the manual : www.php.net/oop5.reflection
Upvotes: 5