Heim  >  Artikel  >  Backend-Entwicklung  >  thinkphp中怎么查看$this是哪个类的对象

thinkphp中怎么查看$this是哪个类的对象

WBOY
WBOYOriginal
2016-06-06 20:44:021194Durchsuche

我是小白。麻烦各位了,
比如我看一个用tp写的网站的源代码,写了个模块,里面有个export的action

<code>class ExamAction extends BaseAction {
    public function export(){   
        $this->isLogin();//判断是否登录
        $str=$this->getProSubStr();
        $sid=session('studentID');
        $this->navtop();
        $this->getSub();//给页面赋值
        ...
        }
}
</code>

怎么看这里的$this是代表哪个对象,里面有哪些值呢?
我都不知道这个$this代表的对象时什么时候被实例化的。。。

回复内容:

我是小白。麻烦各位了,
比如我看一个用tp写的网站的源代码,写了个模块,里面有个export的action

<code>class ExamAction extends BaseAction {
    public function export(){   
        $this->isLogin();//判断是否登录
        $str=$this->getProSubStr();
        $sid=session('studentID');
        $this->navtop();
        $this->getSub();//给页面赋值
        ...
        }
}
</code>

怎么看这里的$this是代表哪个对象,里面有哪些值呢?
我都不知道这个$this代表的对象时什么时候被实例化的。。。

一般来说$this就是你这个类的实例,外层函数new出来这个类的对象之后,就可以调用这个类的非静态方法。$this的东西是不用看的,因为就在你这个类的定义里面。
当然内层函数不知道它在什么情况下被调用,但是作为类方法而言,它知道$this引用会跟普通参数一样被传进来。

PHP5中为解决变量的命名冲突和不确定性问题,引入关键字“$this”代表其所在当前对象。
$this在构造函数中指该构造函数所创建的新对象。
在类中使用当前对象的属性和方法,必须使用$this->取值。
方法内的局部变量,不属于对象,不使用$this关键字取值。
局部变量和全局变量与 $this 关键字,使用当前对象的属性必须使用$this关键字。局部变量的只在当前对象的方法内有效,所以直接使用。

this是指向当前对象的指针

string get_class ([ object $obj ] )

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn