Namespacing and class autoloaders are two important tools provided by PHP that WordPress developers should take advantage of more frequently. I wrote about why, and provided a brief introduction to both of these tools in my last article for Torque. This article offers an in-depth introduction to namespaces in PHP. Namespaces are the better, more flexible version of using unique preferences in your class names. In addition they help structure your directories and allow you to take full advantage of autoloaders that follow the latest standards, including Composer’s autoloader. This article assumes that you’re already familiar with the basics of object-oriented PHP. If […]
Why And How To Use Class Autoloading and Namespacing To Improve WordPress Development
Chris Aprea recently wrote a great post on why WordPress’ (continued) support of unsupported versions of PHP, especially PHP 5.2, is preventing WordPress developers from taking full advantage of the way the language has evolved over the last 8 years or so. Two of the best features in PHP, which WordPress developers have generally shied away from since they were not fully supported by PHP 5.2, are SPL autoloaders and namespacing. These two complementary features make it easier to use small, more manageable, and more easily reusable classes. Technically, PHP has had autoloading since 5.0, but the addition of namespacing […]
8 Comments