首頁 > 後端開發 > php教程 > PHP $this->方法调用

PHP $this->方法调用

WBOY
發布: 2016-06-23 13:32:37
原創
1358 人瀏覽過

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
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板