Page 2 of 2
Re: Is autoload the best practice in PHP now?
Posted: Wed Dec 09, 2009 7:19 pm
by Christopher
That autoload function looks good. What about the idea of having a file containing that function that automatically registers it with SPL? So all you need to do is include the script and it initialized autoloading for you. It could also get the path when initialized so the autoload function did not need to do dirname(__FILE__) for every load.
Re: Is autoload the best practice in PHP now?
Posted: Wed Dec 09, 2009 11:01 pm
by allspiritseve
arborint wrote:That autoload function looks good. What about the idea of having a file containing that function that automatically registers it with SPL? So all you need to do is include the script and it initialized autoloading for you. It could also get the path when initialized so the autoload function did not need to do dirname(__FILE__) for every load.
Sounds great. I would much prefer that as a default (which you could override with your own autoloader) as opposed to inline require_once() every single place a class is used.