Jump to content

spl_autoload functions


fantomel

Recommended Posts

hello guys i got a small questions.. does anyone have an idea how can i handle the errors for spl_autoload function? i don't have any idea how should i build the code for that.. to output an error when the files doesn't exist / class... can someone point me to an article about that without eval() ? or does anyone have an example ?

Link to comment
https://forums.phpfreaks.com/topic/194182-spl_autoload-functions/
Share on other sites

You can use exception handling to report the error. For example (to be used as a guideline, not a fully working and useful script):

 

try 
{
// Try to load class Example
spl_autoload('Example');

// Do something with Example
// ...
}
catch (LogicException $e) 
{
// The class could not be loaded, exit with an error message
die("Error: " . $e->getMessage());
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.