Separation of PHP instructions: A set of commands is responsible for performing a particular action within the code, regardless of the chosen language. A command line indicates the action and the next, sequentially, will then be read, interpreted and enforced. But for this to happen it is necessary that the code interpreter has a point – character – indicating when actually one line ends and when starts another one.

As in C or Perl, PHP requires instructions to be terminated with a semi-colon at the end of each command. However, the closing tag of a block of PHP code automatically implies a semi-colon, it is not necessary to have a point-colon ending the last line of a PHP block. The closing tag will include a new line just after, if it is present.


echo ‘This is a test’;

<?php echo ‘This is a test’ ?>

<?php echo ‘We omitted the last closing tag’;

The closing tag of a PHP block at the end of a file is optional, and in some cases it is useful to omit it, especially when using an ‘include’ or ‘require’. Thus, unwanted white spaces will not appear at the end of the files and you can still add additional response headers. This type of deployment is also useful if you want to use output buffering, where no one wants to have added a blank space at the end of the parts generated by the included files.

Despite the need not to use the PHP closing tag, it is important to pay attention to some points of use:


1)         <?php echo ‘Excluded PHP end tag’;

2)         <?php echo ‘Excluded PHP end tag’;
<p>HTML still visible</p>

In the first example, the code will function normally, as in the following example an error is displayed, whereas a HTML code is written immediately following, without the correct distinction of each type of code. Excluding the need to indicate the end of PHP code only in cases where there are no more code, HTML, for example following.

Another important tip is to use as separators in different lines, as shown in the following example:

echo “First Line”;
echo “Last Line”

The above code would generate an error since the first line possess a finalized command and the line below does not. It is necessary then rewrite this code in the following formats:

echo “First Line”;
echo “Last Line”;


echo “First Line”;
echo “Last Line” ?>

Check out more content on our blog!
Learn all about Scriptcase.

By ,

October 23, 2015


You might also like…

12 IT Trends to Keep an Eye on in 2023

The year 2023 has already started in full swing bringing news and projecting trends for the web dev...

Low-code: it’s the future, not a passing trend

Low-code tools enable professionals to develop fast, efficient, and precise systems. Low-code ha...

What’s new in PHP 8.1

In this article, we will talk a little about the new features, changes, and improvements coming wit...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at Learn more about our Privacy Police.