When should I use parenthesis in require/include statements?(什么时候应该在 require/include 语句中使用括号?)
问题描述
我收到了一堆代码,其中包含很多 require
/include
语句(混合在 require
和 之间)require_once
).有时,路径周围有括号,即require_once (JPATH_COMPONENT.DS.'controller.php');
,有时则没有:require_once $path;
.
I've been handed a pile of code that includes a lot of require
/include
statments (mixed between require
and require_once
). Sometimes, the path has parenthesis around it, i.e. require_once (JPATH_COMPONENT.DS.'controller.php');
, and other times there isn't: require_once $path;
.
包括 提到这一点的 php 文档,但不是具体的.当我找到它们时,我应该删除括号,还是可以不理会它们?在编写进一步的 require/include 语句时,我应该在哪些特定情况下使用它们?
The php docs for include mention this, but aren't specific. Should I remove the parenthesis when I find them, or is it ok to leave them alone? When writing further require/include statements, are there specific cases where I should use them?
推荐答案
你被允许在 'include/require' 中使用括号不是因为 include 允许它本身而是因为你可以在 PHP 中的任何字符串或数字周围使用括号进行分组.
You are allowed to use parentheses in 'include/require' not because include allows it itself but because you can use parentheses around any string or number in PHP for grouping.
例如,"dog"
等价于 ("dog")
,("dog")."dog"
是相当于"dog"."dog"
等
So for example, "dog"
is equivalent to ("dog")
, ("dog")."dog"
is equivalent to "dog"."dog"
, etc.
当您使用涉及计算和字符串连接的复杂表达式时,括号会变得很有用,但在这种简单的情况下,它们只是被允许使用并对单个字符串值执行不必要且无害的分组".
Parentheses become useful when you use complex expressions involving calculations and string concatenations but in such a simple case, they are simply allowed and perform an unnecessary and harmless "grouping" of a single string value.
这篇关于什么时候应该在 require/include 语句中使用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候应该在 require/include 语句中使用括号?
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01