Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spl_autoload_register() performance issues?

I guess there's something i'm missing about the pros of spl_autoload_register() over autoload() . From what i read, the advantage of spl_autoload_register() is that it can be registered multiple times, and then when i instantiate a class it will run trough all the registered autoload functions and load the correct one, which will give me more flexibility and allow me to use different functions for loading classes OR libraries.

But how is this considered a best practice to run over multiple registered functions over a single one?

(Or maybe i just didn't understand it at all)

like image 556
emc Avatar asked Jul 16 '26 15:07

emc


1 Answers

Of course it will be slower if you have several registered autoloaders. However, it better fits modern software development realities, in which many libraries from many different vendors are often included together in the same project. You can only define one __autoload function at a time which can act as an autoloader. However, each package individually can append an autoloader to the spl_autoload chain, without overwriting autoloaders registered by other packages. That's the entire point; it makes the use of autoloaders more flexible without everyone needing to worry about stepping on somebody else's foot.

like image 195
deceze Avatar answered Jul 18 '26 12:07

deceze