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.
Code Tip – Alternate Ternary Operator syntax ?:
The ternary operator can be confusing, as it dehydrates the longer if/else code blocks into a single line of code. It eliminates the repeating pattern. But what about the ?: syntax? How does that work? When should you use it? Check out the other syntax here. This tip is valid for JavaScript and PHP.
Code Tip: Purposeful Naming
Let’s talk about naming of variables, functions, etc. in your code. In this video, you will learn some handy guidelines on naming by intent to let your code express what it’s doing, why it exists, how to use it, and what to expect from it. This tip is valid for all programming regardless of the language or technology.
PHP Tip: What makes a conditional expression false (falsey state)?
In this video, you will learn the intent of this `if` conditional expression as well as what evaluates to false. This is known as checking the falsey state.