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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With