-1

I have seen some articles explaining that a semi colon is not required in the last line of a PHP code due to the closing PHP tag (?>). Is this the case or is there any other theory around it?

Heisenberg
  • 63
  • 9
  • 1
    Just from consistency point of view, I always include a `;`. Is there any reason not to have it? – Nigel Ren Jun 24 '21 at 12:05
  • Never heard of dropping the last semi-colon. My IDE does not like it, and neither does `php -l` when using 7.3. – aynber Jun 24 '21 at 12:06
  • This question: https://stackoverflow.com/q/52757180/14066311 and the doc https://www.php.net/manual/en/language.basic-syntax.instruction-separation.php can help. – Prince Dorcis Jun 24 '21 at 13:45

1 Answers1

0

A semicolon is to denote end of the instruction, and that a new one may start. When a closing tag is found, no new instructions are expected so it's technically not needed.

It's useful in cases like <?= 'foobar' ?> so you don't need to use a semicolon to echo out the string, but <?= 'foobar'; ?> works just as well.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133