if(); do,括号后面的括号是什么? [英] What does if(); do, where the semi-colon is right after the parentheses?
本文介绍了if(); do,括号后面的括号是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在编写一些PHP代码时,我不小心在if语句后面添加了分号;
。例如:
It happens that, when writing some PHP code, I accidentally put a semicolon ;
right after an if statement. For example:
if($a > 1);
{
....
}
我以为PHP应该在这种情况下引发错误,但事实并非如此。这种语法应该有意义,我只是想知道它是什么。
I thought that PHP should raise an error in this case, but it is not. That kind of syntax should have a meaning, I'm just wondering what it is.
我能看到的情况似乎总是如此;
已添加,但我不确定这是什么意思。
For what I could see the condition seems to be always true when the ;
is added but I'm not sure at all this is the meaning.
推荐答案
单个;
可以读作空语句和
if($a > 1);
{
....
}
相当于
if($a > 1)
; // execute an empty statement if $a > 1
// then execute the following block of code.
{
....
}
我可以看到,当
时,条件似乎总是正确的。
已添加
它似乎只是因为块执行无论if语句如何。
It only seems like it since the block is executed regardless of the if-statement.
这篇关于if(); do,括号后面的括号是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文