<?php class A { var $name= 'A'; function main($objC){ var_dump($this);B::request('init', $objC); } } class B { var $name= 'B'; function request($func, $objC){ if (method_exists($objC, $func)){ var_dump($this);$objC->$func($this); } } } class C { var $name= 'C'; function init($pobj){ var_dump($this); } } $objA = new A; $objB = new B; $objC = new C; $objA->main($objC); Output:
object(A)[1] public 'name' => string 'A' (length=1) object(A)[1] public 'name' => string 'A' (length=1) object(C)[3] public 'name' => string 'C' (length=1) I thought $this in Class B always means the object of that Class B. But seems not, can anyone explain: why var_dump($this); in class B, outputs below result not object(B)?
object(A)[1] public 'name' => string 'A' (length=1)
B::requestis astaticcall, not a call to any instance ofB, so the var_dump($this) fromBhas no contect ofBbeing $thisstatic, thought the question was why$thisis defined.