The Importance of the Instruction Terminator at PHP

The instruction terminator at php, also known as the semicolon (;), is absolutely required at the end of commands. The instruction terminator tells the PHP parser, “I’m done with this command, try the next one.”

If you do not end commands with a semicolon, the PHP parser will become confused, and your code will display errors. These next steps show you how these errors come about and, more importantly, how to fix them.

The way of Instruction Terminator at PHP

1. Open a new file in your text editor.

2. Type the following HTML:

<HTML>  <HEAD>  <TITLE>Making an Error</TITLE>  </HEAD>  <BODY>

3. Type the following at PHP code:

<?  echo "<P>I am trying to produce an error</P>"  echo "<P>Was I successful?</P>";  ?>

4. Add some more HTML so that the document is valid:

</BODY>  </HTML>

5. Save the file with the name errorscript.php.

6. Place this file in the document root of your Web server.

Take a look at lines 7 and 8 of the script at php:

echo "<P>I am trying to produce an error</P>"  echo "<P>Was I successful?</P>";

Line 7 does not have an instruction terminator, and line 8 starts a new command. The PHP parser doesn’t like this, and it tells you so by producing the parse error.

This error is easy enough to fix at php:

1. Open the errorscript.php file.

2. On line 7, add the instruction terminator (;) to the end of the line:

echo "<P>I am trying to produce  an error</P>";

3. Save the file as at php.

4. Place this file in the document root of your Web server.

5. Open your Web browser and type http://127.0.0.1// errorscript.php.

After you fix line 7, the PHP parser can deal with the file, and the rest of the output is successful. Avoid this and other errors by paying close attention to things such as semicolons and, as you’ll learn in the next section, quotation marks at PHP!

andcombd