PHP return(value); vs return value; [英] PHP return(value); vs return value;

查看:130
本文介绍了PHP return(value); vs return value;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

return($ var); return $ var; 之间是否有任何区别括号?

Is there any difference between return($var); and return $var; other then wrapping it in parentheses?

推荐答案

除非您通过引用返回,否则它们意思相同。优选地排除括号。从文档

Unless you are returning by reference, they mean the same thing. It is preferable to exclude the parentheses. From the docs:


注意:注意,由于 return()是一个语言结构而不是一个函数,所以不需要围绕其参数的括号。它通常是让它们离开,你实际应该这样做,因为PHP在这种情况下做更少的工作。

Note: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.


注意:在通过引用返回时,不应在返回变量的周围使用圆括号,因为这将不起作用。您只能通过引用返回变量,而不是语句的结果。如果使用 return($ a);那么你不是返回一个变量,而是返回表达式($ a)的结果(当然, $ a )。

Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a).

这篇关于PHP return(value); vs return value;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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