What exactly is php $this

WBOY
Release: 2016-08-08 09:29:31
Original
1367 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!