The intent of global variables is to allow all of the code, all plugins and themes, to be able to both read and write to the variable. You want anything within the website’s PHP code to have full, unprotected access to the data that your variable represents. That means that any code within the website can change the data. For example, $wp_query is a global variable. Therefore, any piece of code in WordPress Core, plugins, and theme can both read and change the data.
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
Variable – PHP Internals
To better understand variables and scope, it helps to look at the PHP internals and how variables are managed in memory. No, this is not a C course. Rather, you will see the concept of how PHP tracks and manages the variables and the data they represent.
Function Parameters
The variable(s) declared within the parentheses of the function itself is called a parameter. You can have both optional and required parameters. Let’s talk about function parameters, why is it called a parameter, its scope, its intent, and how arguments are passed to each parameter.
Variable Scope
Let’s talk about variable scope. Scope defines how and where you can access and use variables. It relates to memory. A variable within a function belongs to that function. Scoping is like a gatekeeper. It protects our code from other functions and code, to ensure we have control. It protects our variable naming to avoid naming conflicts.
PHP Variables Intent and Naming
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 […]
PHP Variables Introduction
This episode introduces you to PHP variables and this bootcamp. You will also find out what you need for this bootcamp, which includes the Non-WordPress Sandbox, which you will use throughout this bootcamp.
PHP Conditional Expressions
Conditional expressions are an essential in programming, yet they are largely misunderstood. In this bootcamp lab, you will discover how complex expressions are evaluated as well as falsey states, assignments in the expression, and much more. Roll up your sleeves as it’s time to dive deep into PHP conditional expressions.
Operator Precedence Experiment
In this episode, you are going to do an experiment to discover the answers and see how the operator precedence actually works. When you combine complex expressions together, each expression is evaluated following the operator precedence. However, which side of the expression is evaluated first? And if one part is false what happens to the other parts? It’s important that you know how your conditional expressions will be evaluated and in what order to ensure you do not get unexpected behavior.
Logical Operator Experiment
Which side of the expression runs first? And when you do an && if the left side is false, does it run the right side? How about an ||? If the left side is true, does it run the right side? In this experiment, you’ll write code that proves the order and which sides actually run for the logical operators. You’ll get some tips too.
Operator Truth Tables
Logical operators work just like their hardware digital gate counterparts. Let’s figure out truth tables to discover how the And, OR, and Xor actually work.