什么时候应该在 require/include 语句中使用括号?

编程入门 行业动态 更新时间:2024-10-27 20:35:09
本文介绍了什么时候应该在 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 语句中使用括号?

本文发布于:2023-10-27 18:23:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:什么时候   括号   语句   include   require

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!