您好,欢迎访问一九零五行业门户网

PHP $this->方法调用

reference: http://docs.php.net/manual/en/language.oop5.late-static-bindings.php
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.
example #1 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();
输出
fatherson
example #2 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();
输出
father
其它类似信息

推荐信息