Answer the question
In order to leave comments, you need to log in
spl_autoload_register how to catch exception?
There is an autoload file autoload.php
here is the contents of the file
try {
set_include_path(get_include_path()
.PATH_SEPARATOR."app/controllers"
.PATH_SEPARATOR."app/models");
spl_autoload_extensions(".class.php");
spl_autoload_register();
} catch (Exception $e) {
echo $e->getMessage().$e->getLine();
}
when a class object is created, the class is automatically connected.
$route = new Route();
in this case, route.class.php is connected The
question is how to make sure that when an object of a non-existent class is created (more precisely, if $temp = new template(); and there is no such file template.class.php) an error is not shown on the screen?
(Fatal error: spl_autoload(): Class Template could not be loaded )
I just need to catch the exception and redirect the person to a 404 page.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question