PHP 函数用 & 符号开头是什么意思? [英] What does it mean to start a PHP function with an ampersand?

查看:30
本文介绍了PHP 函数用 & 符号开头是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用包含以下代码的 Facebook 库:

I'm using the Facebook library with this code in it:

class FacebookRestClient {
...
    public function &users_hasAppPermission($ext_perm, $uid=null) {
        return $this->call_method('facebook.users.hasAppPermission', 
        array('ext_perm' => $ext_perm, 'uid' => $uid));
    }
...
}

什么是 &在函数定义的开头意味着,我该如何使用这样的库(在一个简单的例子中)

What does the & at the beginning of the function definition mean, and how do I go about using a library like this (in a simple example)

推荐答案

函数名前的 & 号表示函数将返回对变量的引用,而不是返回值.

An ampersand before a function name means the function will return a reference to a variable instead of the value.

通过引用返回在以下情况下很有用你想用一个函数来查找引用应该是哪个变量边界.不要使用按引用返回以提高性能.引擎将自动优化此它自己的.仅在以下情况下返回引用你有一个有效的技术理由这样做.

Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so.

请参阅返回引用.

这篇关于PHP 函数用 & 符号开头是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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