【发布时间】:2013-08-28 09:58:32
【问题描述】:
有些人包含这样的文件:
include ('file.php');
有些人包含这样的文件:
include 'file.php';
我认为这里完全没有必要使用括号。你有什么看法?哪种风格更好,为什么?
【问题讨论】:
-
没有意义。第二种方法是强调
include是一种语言结构。
标签: php syntax coding-style
有些人包含这样的文件:
include ('file.php');
有些人包含这样的文件:
include 'file.php';
我认为这里完全没有必要使用括号。你有什么看法?哪种风格更好,为什么?
【问题讨论】:
include 是一种语言结构。
标签: php syntax coding-style
当不需要括号时,最好将其删除(return 与 return () 相同,性能更好)。包含可能相同。
http://php.net/manual/en/function.return.php
Note: Note that since return is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.
此外,使用完整路径进行包含比仅使用相对路径更好。
【讨论】:
有点无关紧要,因为解析器同时接受两者(因此我怀疑你很可能有更紧迫的问题),但如果你想正确,你应该不带括号使用它,因为 include 是语句不是函数。
根据PHP include manual page(强调我的):
include 语句包含并评估指定的文件。
【讨论】: