Reference: http://docs.php.net/manual/en/language.oop5.late-static-bindings.phpphp
Note: In non-static contexts, the called class will be the class of the object instance. Since
$this->
will try to call private methods from the same scope, using static:: may give different results. Another difference is that static:: can only refer to static properties.oop
class Father { public function __construct() { $this->init(); } private function init() { echo 'father' . PHP_EOL; } } class Son extends Father { public function __construct() { parent::__construct(); $this->init(); } private function init() { echo 'son' . PHP_EOL; } } new Son();
輸出this
father son
class Father { public function __construct() { $this->init(); } private function init() { echo 'father' . PHP_EOL; } } class Son extends Father { private function init() { echo 'son' . PHP_EOL; } } new Son();
輸出.net
father