PHP Namespace gives you the means to encapsulate your code modules to improve readability and prevent code naming collisions. In this hands-on lab, you will migrate from prefixing convention to PHP namespacing. You will learn the ins and outs of namespacing.
WordPress’ de facto is to use “prefixing” to avoid name collisions. Why? Because WordPress started before namespaces were available in the PHP scripting language. PHP introduced namespacing in version 5.3.0. You can learn more about it in the official PHP documentation.
What Will You Learn?
In this hands-on lab, you and I are going to ease into namespacing. You’ll learn about:
- Why use PHP namespacing
- The problem and potential of naming collisions
- Problems of prefixing
- How namespacing enhances readability, reusability, and maintainability.
- The syntax and placement in files/li>
- The naming conventions
- Naming within a namespace
- Using code from another namespace
- Importing and aliasing
- How to convert a plugin from prefixing to namespacing
- and more
You will learn as you write code, as it’s the best way for you to learn.#PHP namespace is a better naming convention than prefixing. Come learn about it for #WordPress Click To Tweet
If you listen carefully, you can hear the 1s and 0s flowing in your computer.
Total Lab Runtime: 02:25:26
- 1 Lab Introductionfree 02:59
- 2 What and Why of Namespacingfree 20:15
- 3 Why Namespacing instead of Prefixing?free 12:39
- 4 The Basicspro 17:36
- 5 Fully Qualified Namingpro 06:50
- 6 Callbacks and Namespacingpro 08:00
- 7 Name Resolution Rulespro 12:17
- 8 Using Functions from Another Namespacepro 16:37
- 10 Class Basicspro 12:20
- 11 Practical Example: Convert from Prefixingpro 10:08
- 12 Real World Example: Convert from Prefixingpro 06:14
- 13 Architecture - Building in Packages and Modulespro 08:59
- 14 PHP Examples - Laravel & Symfonypro 02:50
- 15 Wrap it Upfree 07:42
In order to be proficient in PHP, you need to first know variables. It's learn and do time. In this lab, you are focusing on user-defined variables, the data they represent, how they are passed and assigned into function parameters' list, naming, and their scope. For Pro members, you learn more about the PHP internals, how variables are linked to their data, and how memory moves around under the hood.
Check out the PHP Library for more hands-on labs, insights, Docx, and more.