Syntax Basics
Lab: PHP 101: Gentle Introduction to WordPress Programming
Video Runtime: 18:34
Before you do this episode, go watch the Fundamentals of Syntax. Seriously, do it now. This episode will help you to understand what it is and why we need syntax.
Your natural language needs a set of rules in order for you and me to understand one another. We put sentences together based upon those rules. For example, if I said:
“Tonya woman engineer”
would you know what I was talking about or the context of what I meant? Not necessarily. Why? Because it’s not a complete sentence. It’s just words. We need to understand the basic rules of language in order to properly communicate and understand the meaning.
This applies to programming too. Programming languages use rules too in order to process and run your code. The rules are called syntax.
Remember, computers are stupid, but fast. They cannot infer, reason, think, or figure out what the heck you meant to type. If you misspell an instruction or variable, the language and computer cannot say “Well, I know that you meant to type add_action
even though you actually typed add_actin
. So I’ll go ahead and run the right instruction.” No, computers don’t do that unless you write a program to do it.
Key Points
Your job as a developer is to solve problems and get the computer to do what you want. Syntax is a key part of that, as the programming language uses it to know what you want to do.
Remember, computers are stupid, but fast. It’s a box of digital circuits that runs software.
It can’t infer, reason, think, or figure out what you meant for it to do.
It runs what you tell to do it. Period.
PHP defines a set of rules about how you structure an instruction. Remember that the computer runs one instruction at a time. You are telling the computer what to do, step-by-step, one instruction at a time.
The PHP interpreter first has to identify what you what it to do. What task do you want it to run? It uses the syntax to parse out the task. And then it runs it.
In this episode, we’ll talk about syntax, what it is, and why you need to learn to properly structure your code. Then we’ll talk about some basics such as:
- End of instruction with a semi-colon ;
- Parentheses for passing information to be worked on or stored
- Code block declarations using curly braces {}
- Telling PHP “Hey, this code is PHP” using
<?php
Test Your New Knowledge
-
Why does syntax matter in programming?
-
How does PHP know that the code is actually PHP and not HTML or something else?
-
Why do instructions need parentheses?
Learn More
Here is a FREE lab that teaches you about syntax in a more language agnostic approach.
When was the last time you got out of your chair and stretched? Just saying…
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