PHP 返回(值);vs 返回值;

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

问题描述

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 返回(值);vs 返回值;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)