Reading time: 10 minutes

Technical preparation: Basic PHP syntax

This is called advanced syntax, but it is still basic syntax, just to make a difference from the previous one. (No matter how advanced things are in the programming world, they always become basic under the wheel of time.)

This section focuses on PHP operators, functions, and object orientation.

$a=$b+$c; I’m going to skip the basics and focus on some of the nuances of PHP.

Operator

Most of the operators of modern programming languages are implemented in PHP, and I’ll focus on the “==” and “===” operators that are unique to weakly typed languages.

Strongly typed languages typically only have the “==” operator, so why do weakly typed languages need the “===” operator?

This is because in weakly typed languages such as PHP, when the number 0 is compared to the string “0”, PHP automatically converts the string to a number for comparison, that is, 0==”0″ returns true. (What rules does PHP use to convert strings to numbers when comparing them?)

The “===” operator will check the type of the variable on either side and return false if the type is not the same.

In the same way, judgment does not equal “! = “and”! == “two comparison operators.

Exercises after class:

FALSE==””;

0==”0abc”;

0 = = “0123”;

0 = = 0.0;

0 = = [];

“0abc==””;

‘ ‘= = “”;

If these can do all right, then this close you will cross over, need the answer to the children’s shoes in the public number to zhao tong shoes message oh.

Second, the function

In PHP, all functions need to be identified with the function keyword.

Such as:

function fun() {echo "HelloWorld!!!";
}
Copy the code

Methods in the class come with a $this variable that indicates the object on which the method is being called. (Do you remember the difference between a function and a method?)

In many programming languages, method calls are made using “. Notation to do it.

Such as:

this.sayHello();

But in PHP, “. Operators are already used as string concatenators, so you need to use the -> symbol to call a method. Isn’t that pretty graphic?

Such as:

$this->sayHello();

In functions, I want to focus on two commonly used built-in functions in PHP: empty() and isset().

Many PHP beginners will often confuse the use of these two functions.

First, the official explanation of the empty() function:

Return FALSE if var exists and is a non-empty non-zero value otherwise return TRUE.

The following are considered empty:

  • “” (empty string)
  • 0 (0 as an integer)
  • 0.0 (as a floating point 0)
  • “0” (as a 0 in the string)
  • NULL
  • FALSE
  • Array () (an empty array)
  • $var; (a variable that is declared but has no value)

Then there is the official explanation of the isset() function:

Return TRUE if var exists and the value is not NULL, FALSE otherwise.

Some people may still be confused after reading the explanation, but the difference between them is the NULL value.

  • This is used when we need to determine whether a variable has been declared but its value is nullempty()Delta function.
  • This is used when we need to determine whether a variable is undeclared or NULLisset()Delta function.

Third, object-oriented

PHP object orientation is all about inheritance and polymorphism and superclasses and subclasses and why it’s so tiring, but like most programming languages, I’m not going to write it.

Just kidding, object orientation is the current trend in programming languages, and even Javascript has supported Class writing since ES6.

But I personally find it tedious to talk directly about object orientation, and it’s easy to confuse a beginner with constructors, destructors, inheritance, polymorphism, etc., and more often it’s just “Oh, so what?” The experience was forgotten in two days.

So I think if you have experience in other languages, you don’t need to go over it again, but if you are a beginner, you will understand it more easily and experience it in a completely different way.

Four, summary

The syntax of PHP is basically covered in two chapters.

What? You said it was that short? A lot of grammar tutorials take more than four or five classes, right?

That is very normal, because Zhao skipped a lot of details, I think the most efficient way to start a new knowledge is to spend only 20% of the time to learn 80% of the knowledge that is often used, and we will gradually supplement a lot of details later.

What? You don’t think you learned anything?

That is also very normal, can look at all understand all grasp is always very few people, a lot of knowledge after a lot of practice to truly understand.

In the following chapters, we will jump directly into the study of frameworks.

—– End —–

More oliver

Please scan the qr code below

Welcome to pay attention ~