fantomel Posted March 4, 2010 Share Posted March 4, 2010 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/194182-spl_autoload-functions/ Share on other sites More sharing options...
salathe Posted March 4, 2010 Share Posted March 4, 2010 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/194182-spl_autoload-functions/#findComment-1021686 Share on other sites More sharing options...
fantomel Posted March 5, 2010 Author Share Posted March 5, 2010 and if i would like to throw an error with file not found without triggering an error "class not found" how could i do ? Quote Link to comment https://forums.phpfreaks.com/topic/194182-spl_autoload-functions/#findComment-1021873 Share on other sites More sharing options...
salathe Posted March 5, 2010 Share Posted March 5, 2010 You can do whatever you like after catching the exception thrown from spl_autoload. Dieing with the exception message, as in my code above, was just an example -- you're free to do whatever you like at that point. Quote Link to comment https://forums.phpfreaks.com/topic/194182-spl_autoload-functions/#findComment-1021878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.