Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Allowing for multiple autoloaders #44

Closed
fivefilters opened this issue Jun 5, 2013 · 1 comment
Closed

Allowing for multiple autoloaders #44

fivefilters opened this issue Jun 5, 2013 · 1 comment

Comments

@fivefilters
Copy link

I'm working on a new project and I'm trying out Swiftlet - I like it very much so far. One problem I encountered, however, is the autoloader.

/Swiftlet/App.php has an autoload function which is registered using spl_autoload_register. But it seems the autoload function makes no attempt to check if the file exists. So if I run some code using class_exists, the autoload function will attempt to load the file, resulting in an error.

Another problem related to this is being able to register multiple autoloaders. In another issue - #40 - you suggest copying and modifying the autoload function from /Swiftlet/App.php and updating the call to spl_autoload_register to use the new function. But considering the documentation for spl_autoload_register states:

If there must be multiple autoload functions, spl_autoload_register() allows for this. It effectively creates a queue of autoload functions, and runs through each of them in the order they are defined.

I think it might be better to allow users to register their own autoloaders to run in combination with Swiftlet's. And for that to work properly, it seems there needs to be a check for the existence of the file before requireing it. I've done this myself by extending Swiftlet/App and overriding the autoload function to add: if (file_exists($file)) require $file;

@AliasIO
Copy link
Owner

AliasIO commented Jun 5, 2013

I completely agree, fixed in d96d193.

@AliasIO AliasIO closed this as completed Jun 5, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants