3.3. Use a semicolon

The set of programming language constructions ending with a semicolon will be called an expression.

As you can see from Listing 3.3, the semicolon is not indicated after the line “Displaying the current date”. The expression is one, and there is no need to separate it from other expressions. However, as can be seen in the second inset, there is a semicolon at the end of each echo construct. If you forget to specify this delimiter, the PHP programming language interpreter will consider the expression on a new line a continuation of the previous one and will not be able to correctly parse the script.

As a result, the error message will be generated:

"Parse error: syntax error, unexpected 'echo' (T _ ECHO), expecting ',' or ';"

The last expression before the final tag ?> Can be omitted from the semicolon. For example, in Listing 3.3, after the echo date(DATE_RSS) expression, the semicolon can be omitted. However, it is strongly recommended not to use this feature and to put semicolons after each expression, since the addition of new operators may lead to the appearance of intractable errors.

String translations do not affect the interpretation of the script, the expression can be split into several lines – the PHP interpreter will assume that the expression is completed only after it detects a semicolon or the ending tag ?>. In listings 3.5 and 3.6, there are two scripts that are similar in functionality.

Listing 3.5. Use a semicolon. Semicolumn.php file

echo 5 + 5;
echo 5 - 2;
echo "Hello, world"; 

Listing 3.6. Alternative script entry from listing 3.5. File mech.php

echo 5
5; echo 5 -
2; echo "Hello, world!" 

Constructions like the one shown in listing 3.6 should be avoided. The more clearly and expectedly the code is written, the easier and faster it is to debug.