Check if a PHP class exists

1 · Josh Sherman · July 24, 2013, midnight
We’ve discussed how to check if a class has a function but what if the class doesn’t exist at all? To check if a class exists you can use, use guessed it, class_exists(). if (class_exists('MyClass')) { $object = new MyClass(); } else { throw new Exception('The class MyClass does not......