【问题标题】:What's the difference between include('file.php') and include 'file.php'include('file.php') 和 include 'file.php' 有什么区别
【发布时间】:2012-09-28 23:22:24
【问题描述】:

include('file.php')include 'file.php' 都有效,而且似乎可以互换。

有谁知道这两种语法有什么区别吗?表现?在特定版本中引入?

我知道如果你要写include $_SERVER['DOCUMENT_ROOT'] . '/file.php';,写include($_SERVER['DOCUMENT_ROOT'] . '/file.php'); 可能看起来更清晰

【问题讨论】:

标签: php syntax


【解决方案1】:

没有区别。这些是“语言结构”。从语法上讲,这意味着它们可以带或不带大括号使用。一个例子是echo 语句。

echo("hello");echo "hello"; 是一样的

【讨论】:

    【解决方案2】:

    没有区别,因为include 是一种不需要括号的语言结构,就像echo

    另请参阅:include - 向上滚动一点

    【讨论】:

      【解决方案3】:

      include('file.php') :首先计算('file.php')的值,因为值是file.php,然后将file.php包含到当前文件中; include 'file.php' :直接将file.php包含到当前文件中。 如你所见,结果是一样的,但是第二种方式效率更高。

      【讨论】:

      • 效率没有区别。
      猜你喜欢
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多