Let’s talk about what is the intent of variables, syntax, and naming standards.
What is a variable? A variable is a symbol that represents data. It represents some value. It’s variable because you can change its value by reassigning it another value.
For example, if you had a variable
$post_id = 10;, you can change the value of the variable by doing
$post_id = 20;. It’s the same variable, but you varied the value by assigning it a new value.
Why is it a “symbol?” A symbol lets us define an alphanumeric symbol that we can read. It “represents” something else.
For example, let’s say the data is
10. Okay, imagine reading code and you see the value only. How would you know what it means and this value stands for? You wouldn’t. Instead, you give context and a meaning with a human-readable symbol that you define. Let’s say that the data represents the number of posts you want to show on a page. You might call the variable
$number_of_posts. Now that
10 has more meaning to you as you read the code.
Why is it human readable? We make it human readable so that you and I can understand and read the code to understand what value the variable represents.
Higher level languages let you and I define the naming for our code. We can make it readable so that our code is expressive and tells us what it’s doing.
For example, let’s say you have a variable named
$a. What does that variable represent? Huh, I don’t know. Do you? No, we’d have to add a bunch of comments to tell us what that variable means. Instead, you’d make it readable, purposeful, and meaningful. Make the variable tell you what value it represents.
So you can change
$a to be
$number_of_posts, if that’s what it represents.
You have the power to name variables.#PHP variables represent a value. Make them human readable, purposeful, & meaningful. #WordPress Click To Tweet
Once upon a time, there was a developer... You! This is going to be a good story...
Total Lab Runtime: 01:50:52
- 1 PHP Variables Introductionfree 03:44
- 2 PHP Variables Intent and Namingfree 12:43
- 3 Variable Scopebasic 08:24
- 4 Function Parametersbasic 08:46
- 5 Variable - PHP Internalspro 11:08
- 6 Global Variablesbasic 09:10
- 7 Global Variables - PHP Internalspro 02:52
- 8 Static Variablesbasic 13:05
- 9 Static Variables - PHP Internalspro 05:01
- 10 Passing Variables By Referencepro 10:04
- 11 Passing Variables By Reference - PHP Internalspro 08:01
- 12 Namespacingbasic 01:37
- 13 Variable Scope When Including Filesbasic 08:24
- 14 Type Jugglingbasic 07:53