Is there a problem with omitting the semicolon in a php tag with an expression only

Question:

When using php along with html, I know it works to omit the ";" in one-line php tags, but is there any problem this may cause?

Omit the ";" is it good practice or not?

<?php algumaFuncao() ?>

Where

<?php algumaFuncao(); ?>

EDIT

The question is for tags with an expression to be validated only, sorry for not specifying this earlier.

Answer:

In cases like expressions using the alternative syntax, I don't use the ; .

Example:

<?php foreach($array as $value) : ?>
<?php endforeach ?>

Some programmer friends criticized the lack of ; after the endif , but I'm sure no one would use one ; after closing a common if .

So:

<?php if  ($x) { ?>

<?php }; ?>

I believe you are referring in your question to expressions, such as a simple echo , or a function call.

It is highly recommended to use the ; in these cases.

I tend to look at the source code of frameworks a lot, so I can try to improve my coding pattern. And looking at the Laravel 4 source code, I could see what it does when using Blade's syntax.

Example of a Blade code:

Meu nome é {{ $nome }} e tenho {{ $idade }} anos

Blade compiles the code like this:

Meu nome é <?php echo $nome; ?> e tenho <?php echo $idade; ?>

So we realized that this framework bothered to put the ; at the end of the expression.

Scroll to Top