The other day, I tweeted out that I believe there is hesitancy in the WordPress world to use autoloaders. Don’t believe me? I feel like there’s hesitancy in the WP world w/ autoloaders. spl_autoload_register is your friend. Namespaces NOT required. — Justin Sternberg (@>) February 25, 2015 I think there is hesitancy mostly because of lack of knowledge, but I also think there’s a bit of misinformation/misunderstanding, so I’m going to do my best to clear some things up in this post. To be clear, this is an advanced developer topic, and if you’re just getting started with OOP (Object Oriented Programming), then I’d suggest heading over to this post instead. But if you’re just past that OOP n00b stage, or even if you’ve been around the block, there’s a decent chance you haven’t yet taken advantage of an autoloader. At best, you’re require-ing all you’re other files, and at worst, you’re stuffing all your functionality into one god-class (say it ain’t so!). One common file-load pattern is the ‘include all-the-things’ pattern. It looks like this. You could make the argument that it gets the job done, but you’re not earning any DRY style points in the process, and you’re definitely not optimizing,
Share This