We need a “safe” version of PHP’s “class_exists” because Magento has a bug (or they call it a “feature”). Magento is throwing an exception if you do class_exists() on a class that ends with “Factory” and if that file does not exits.
Description
This function catches all potential exceptions and makes sure to always return a boolean.
Parameters
$classstringrequired
Source
public static function safeClassExists($class)
{
try {
return class_exists($class) || interface_exists($class);
} catch (\Exception $e) {
return \false;
}
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.