最好使用require_once('filename.php')或require_once'filename.php';

问题描述 投票:32回答:4

这仅仅是样式上的差异,还是使用require_once('filename.php')require_once 'filename.php'会产生实际的负载/效率差异?

php require-once
4个回答
17
投票

这是完全一样的东西。这是风格问题。

括号有时会挡住。例如,手册中的此示例未达到您的期望:

if (include('vars.php') == 'OK') {
    echo 'OK';
}

请参见example #4


30
投票

梨编码标准说:

“ include_once和require_once是语句,不是函数。括号不应包含主题文件名。“

来源:http://pear.php.net/manual/en/standards.including.php


10
投票

你的心告诉你什么?

性能差异,如果有:可以忽略不计。


7
投票

没有区别。我不使用括号,因为它们不是必需的。 require_once是没有功能的。

© www.soinside.com 2019 - 2024. All rights reserved.