我这里需要结尾的分号吗? [英] Do I need a trailing semicolon here?
问题描述
示例:
<?php $formElement->display()?>
可以吗?还是应该提供; ? 好吧,我猜想PHP解释器足够聪明,可以看到该行已完成,并且由于末尾的?>而使表达式完成了.对吧?
Is this fine, or should I provide a ; ? Well I guess that the PHP interpreter is clever enough to see that the line is finished and the expression done because of the ?> at the end. Right?
推荐答案
它不是必需,但是您应该把它作为一个好习惯.
It is not required, but you should put it, as a good practice.
那样,您需要在该指令之后添加另一条指令的那一天,它将很好地工作.
That way, the day you need to add another instruction after this one, it'll work fine.
这是回答您问题的手册页:指令分离 (引用,强调我的意思):
And here is the manual's page that answers your question : Instruction separation (quoting, emphasis mine) :
与C或Perl中一样,PHP要求在每个语句的末尾以分号终止指令.
一段PHP代码的结束标记会自动表示一个分号;您不需要使用分号终止PHP块的最后一行.
该块的结束标记将包含紧随其后的换行符(如果存在的话).
As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement.
The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block.
The closing tag for the block will include the immediately trailing newline if one is present.
这篇关于我这里需要结尾的分号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!