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?
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?
Use reflection. ReflectionClass
->isAbstract()
Use it like this:
$class = new ReflectionClass('NameOfTheClass');
$abstract = $class->isAbstract();
If you need to check this in runtime, I'd suggest you re-evaluate your application architecture.
You should never try to do this unless you're building an extremely complex application to inspect other code you cannot change.
<?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