Is autoload the best practice in PHP now?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
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?

Post 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.
(#10850)
User avatar
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?

Post 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.
Post Reply