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.

Example:

<?php
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:

Example:

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:

<?php
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:

<?php
echo “First Line”;
echo “Last Line”;

or

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

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

By ,

October 23, 2015

a

You might also like…

No-code: Ease or Trap? What no one tells you about creating without coding

With the popularization of No-code and Low-code platforms, application development has reached a po...

Top 10 Rapid App Development Tools You Need to Know

In this highly fast-moving digital world, rapid application development tools must be available to ...

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 sales@scriptcase.net. Learn more about our Privacy Police.