Ila*_*ste 4 php coding-style conditional-statements
在PHP中,我知道单语句条件不需要大括号.但这个问题是关于良好的编码风格.(当然在谈论风格时,通常最好只使用项目中的一致风格,但是让我们忽略这个问题.)
所以:用大括号括起任何条件语句是更好的形式,还是在简单条件下不使用括号更好(例如更干净):
例如:
if (!file_exists($templatefile)) {
throw new Exception('Template file does not exist');
}
Run Code Online (Sandbox Code Playgroud)
或这个:
if (!file_exists($templatefile))
throw new Exception('Template file does not exist');
Run Code Online (Sandbox Code Playgroud)
对此有任何共同的一致良好做法,还是仅仅取决于个人喜好?
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |