An example Analysis of the nearest principle of $this in php
This article mainly explains "the example analysis of the nearest principle of $this in php". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn the "example Analysis of the nearest principle of $this in php".
Description
1. The nearest principle of $this applies not only to the private attribute, but also to the private member method.
2. $this refers to the object being called, but when dealing with private properties and methods, it follows the principle of proximity and refers to the class to which the method belongs.
Example
Class AA {private function foo () {echo "success!\ n";} public function test () {$this- > foo (); static::foo ();}} class BBBB extends AA {} class CCC extends AA {private function foo () {echo 'CCC';}} $b = new BBBB (); $b-> test (); / / Success Success$c = new CCC (); $c-> test () / / Success error:Call to private method CCC::foo () from scope AA so far, I believe you have a deeper understanding of "example Analysis of the nearest principle of $this in php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!