Next, let’s talk about PHP name resolution rules. That means: how PHP figures out what code to run for the given name. If you look at the PHP Manual, they give you a techie write-up that likely will confuse you. Essentially, here’s what you need to know:
- How you declare the function is the starting point. If you include the fully qualified name, you are telling PHP exactly which function you want; whereas, if you leave off the namespace, then it walks through its process ordering to figure out which function to run.
- You can name using:
- Unqualified name: no backslash or namespace, i.e. just the function
- Qualified name: the full namespace + function but without the starting backslash
- Fully qualified name: the starting backslash + full namespace + function
- Relative name: its relative to the current namespace, e.g.
Sandbox\get_the_ID()when used in
Let’s walk through it in this episode.
Your functions are bloated. Put them on a diet. Think "skinny" and "as few lines as possible."
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