Web Development Tutorials




  
  

Instruction Terminator

Each line of code in PHP must end with an instruction terminator also know as the semicolon (;). The instruction terminator is used to distinguish one set of instructions from another.

Failure to include the instruction terminator causes the PHP interpreter to become confused and display errors in the browser window. The following code segment shows a common instruction terminator error:

<!DOCTYPE html>
<html>
<head>
    <title>A Web Page</title>
</head>
<body>
 <p>
    <?php
     echo "This line will produce an error";
     echo "The previous line does Not include an instruction terminator";
 ?>
 </p>
</body>
</html>
        

In this example, the first echo statement is missing the instruction terminator. Because the PHP interpreter cannot determine the end of the first echo statement and the beginning of the second, an error occurs. Depending on the interpreter's Error Handling settings, an error will be displayed or the browser simply displays a blank page.

The following is a typical error displayed when the instruction terminator is omitted:

Parse error: syntax error, unexpected T_PRINT in C:\ApacheRoot\test.php on line 11

                  

As you can see, PHP error messages tend to be rather cryptic in nature. The omission of the instruction terminator is common among developers new to PHP. Over time, it will become common practice to check each line for an instruction terminator.


TOP | NEXT: Commenting Your Code