Naming Stuff
Lab: PHP 101: Gentle Introduction to WordPress Programming
Video Runtime: 06:18
Throughout this lab, you learned about how to name variables and functions. It’s part of the syntax. But let’s go a little deeper.
Names must be unique. Why? If you have two functions that are named exactly the same, how would PHP know which one to run? Think about it. It wouldn’t know which one you want. Aha! Therefore, you give unique names to functions, classes, etc.
In WordPress, the defacto approach is to use prefixing. Why? In a nutshell, it gives a unique suffix to a function to avoid naming collisions. What do I mean by naming collisions? That’s where two (or more) functions have the exact same name. Using prefixing, you are making the name unique because it starts with your company, theme, or plugin’s name.
Think about that. If some other theme or plugin uses the same name, PHP will throw a fatal error. But by giving it a unique name with either prefixing or Namespacing, you’ve made your code unique and different from everyone else’s code.
Does that make sense? If no, go to the Pro Forums and ask me.
You get WET when you swim. Stay DRY when you code.
Episodes
Total Lab Runtime: 03:21:32
- 1 Lab Introductionfree 11:37
- 2 What is PHP? Why use it?free 17:49
- 3 Why and how does WordPress use PHP?free 07:33
- 4 Syntax Basicsfree 18:34
- 5 What's the deal with Variables?free 27:05
- 6 Break Up Code into Logical Partsfree 07:55
- 7 Subroutines - Behold the functionfree 14:11
- 8 Loading Files to Runfree 13:20
- 9 To Run or Not to Run - Making Decisionsfree 19:07
- 10 Sequencing - Yup, code runs in orderfree 06:16
- 11 Repeating code using Loopsfree 13:57
- 12 Building Strings with Dots and Variablesfree 15:10
- 13 What's the deal with scope?free 08:34
- 14 Naming Stufffree 06:18
- 15 Putting it All Togetherfree 08:33
- 16 Where do I go from here?free 05:33