Here is an example of what happens when a class method is called in the wrong way. You will see some warnings when this code is executed, but it will work and print: "I A: print property B". (Done in php5.6)
class A { public function aMethod() { echo "I'm A: "; echo "printing " . $this->property; } } class B { public $property = "B property"; public function bMethod() { A::aMethod(); } } $b = new B(); $b->bMethod();
This means that the variable $ this, used in a method that is called as a static method, points to an instance of the calling class. In the above example, there is a $ this-> property used in class A that points to property B.
Nicolai Nita May 17 '17 at 8:28 2017-05-17 08:28
source share