Is autoload the best practice in PHP now?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Is autoload the best practice in PHP now?
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.
(#10850)
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Is autoload the best practice in PHP now?
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.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.