-3

有些人包含这样的文件:

include ('file.php');

有些人包括这样的文件:

include 'file.php';

我认为这里完全没有必要使用括号。你有什么看法?哪种风格更好,为什么?

4

2 回答 2

1

当括号是不必要的时,最好删除它们(相同的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.

此外,为您的包含使用整个路径比仅使用相对路径更好。

于 2013-08-28T10:00:21.493 回答
0

有点无关紧要,因为解析器同时接受两者(因此我怀疑你很可能有更紧迫的问题),但如果你想正确,你应该在不带括号的情况下使用它,因为include语句不是函数。

根据PHP 包括手册页(强调我的):

include语句包含并评估指定的文件。

于 2013-08-28T10:00:56.227 回答