I am currently working on a Laravel project and I have a bit of code where I want to throw an exception if the class of the given type cannot be found.
$className = $type . 'Field';
if (!class_exists($className))
{
// Throw exception
}
However my IDE (IntelliJ) is giving me auto-complete for 3 different classes belonging to different packages that all have the same name.
Prophecy\Exception\Doubler\ClassNotFoundException
Symfony\Component\Debug\Exception\ClassNotFoundException
PhpSpec\Exception\Fracture\ClassNotFoundException
What is the difference between these and which one should I use in this scenario and why?
You should be using Symfony\Component\Debug\Exception\ClassNotFoundException
.
Other two Exception handlings are for PhpSpec (Testing) and Prophecy (a mocking framework for phpspec).
Since you are trying to throw an exception for ClassNotFound
, you should be using the Symfony Exception Handler.