Home  >  Article  >  Backend Development  >  What exactly is php $this

What exactly is php $this

WBOY
WBOYOriginal
2016-08-08 09:29:311366browse

General statement: ¥this represents the current class object. This is very unclear.

$this depends on the execution object (environment) when the method where ¥this is located is called.

Method execution environment: In which object environment the current method is executed, the The ¥this of the method represents the object. For the object that restores the original method layer by layer, for example

class A{

                                                                                                            echo 'aa'; public function run(){
                var_dump($this);
      }
}
$ai = new A();
$ai->run();
echo "
===== ==
";
class B{
              public function m(){               var_dump($this); A::run();
}
}
$li = new B();
$li->m();
?>


But if it is inherited, it will be calculated separately. This run method comes from inheritance, so this is the class a. $this-> m (); ();
$li- >run();
?>


The above introduces what php $this is, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Types - PHP Manual NotesNext article:Types - PHP Manual Notes