A Crash-Course in PHP Namespaces for WordPress Developers

By Steve Grunwell

Elevator Pitch

For having such a large market share, there a number of more modern PHP features that are completely unknown by most WordPress developers.

This talk introduces the concept of PHP namespaces, forever doing away with “myplugin_” prefixes or unnecessary classes as pseudo-namespaces.

Description

Way back in 2009, PHP 5.3 was released to the world and with it brought support for PHP namespaces — a way of easily separating your code from other developers’ code, which has since become the de facto way of encapsulating functionality across the PHP ecosystem.

With namespaces, multiple packages could use the same class and function names without conflict, because each one would operate in their own PHP namespaces. Unfortunately, many PHP developers who focus on WordPress development may be in the dark on this extremely useful language feature.

This talk aims to shed light on PHP namespaces, especially targeted at WordPress developers who haven’t yet encountered them. Attendees will leave the talk with a firm grasp on PHP namespaces, how they work, and how they can be implemented in plugins and themes.

Notes

Slides, presentation history, and reviews: https://stevegrunwell.com/slides/php-namespaces

Based on my article of the same name, which reached the front page of Hacker News on May 7, 2018.