Why is the semicolon optional in the last statement in php?

后端 未结 3 510
春和景丽
春和景丽 2020-12-03 16:32

I was surprised when I ran the following code in my editor:


As it can be easily see

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 17:08

    Because the semicolon tells the parser that you've reached the end of that instruction. It lets it know that the next piece of text is a new instruction. However the closing tag tells it that we're at the end of all instructions, you don't need to parse anything else. Because we're not parsing anything else we don't need the end of instruction semicolon, it's implied.

提交回复
热议问题