$ this关键字是什么意思? [英] What is $this keyword meant for?

查看:98
本文介绍了$ this关键字是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请向我解释$this->代表什么...让我们以以下代码为例...

Please explain me that for what $this and -> stands for...lets take the example of following code...

$this->convertNamesToCaptions($order, $formId)

推荐答案

$ this指向当前对象

$this refers to the current object

手册说:

当从对象上下文中调用方法时,伪变量$ this可用. $ this是对调用对象的引用(通常是该方法所属的对象,但如果从辅助对象的上下文中静态调用该方法,则可能是另一个对象).

The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

小例子:

class Test
{
    private $var;

    public function func()
    {
        $this->var = 1;
        return $this->var;
    }
}

$obj = new Test();

$obj->func();

这篇关于$ this关键字是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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