note 124890 rejected from language.basic-syntax.instruction-separation by cmb
| From: | cmb@php.net | Date: | Wed, 08 Apr 2020 06:31:20 +0000 |
| Subject: | note 124890 rejected from language.basic-syntax.instruction-separation by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214429@lists.php.net to get a copy of this message | ||
Note Submitter: developer-pm at protonmail dot com
----
Note: If you do not add the closing tag like so you will get a parse syntax error
(This will produce a syntax parse error)
<?php echo "hello world"
(Valid statement, omitting the trailing semicolon)
<?php echo "hello world"?>
If you have multiple statements for example
<?php
echo "hello world"
echo "hello earth"
?>
The code above will produce a parse error the only way to omit the semicolon in a multiple php
statement program will be to terminate each php statement with the semicolon besides the last
statement in your php code block. (example below of a valid multiple php statements omitting the
semicolon)
<?php
echo "random text";
echo "more random text"
?>
I do not recommend this type of programming style, and you shouldn't either. It is always best
to add the trailing semicolon behind each statement even if you have only one single line statement.
By adding the semicolon to each statement you and your users will run into less errors. Specially if
you have a large program, looking for a missing semicolon will be time consuming. This example is
just to demonstrate how to omit the semicolon. (which again is not recommend at all)