我何时应在require/include语句中使用括号? [英] When should I use parenthesis in require/include statements?

查看:82
本文介绍了我何时应在require/include语句中使用括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一堆代码,其中包含很多require/include语句(在requirerequire_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语句中使用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆