小弟我覺得好迷糊

來源:互聯網
上載者:User
我覺得好迷糊啊
PHP code
 * Foo * cB * Tango * cC * Foo * cD *  * What the hell?! :) */?>



這是覆蓋,還是什麼啊?為什麼輸出這樣啊,不能理解啊,聽亂的啊。

------解決方案--------------------
這叫什麼呢?自找麻煩!
為累而累
------解決方案--------------------
不理解就算了,無所謂的事。
------解決方案--------------------
探討

這叫什麼呢?煮餃子找麻煩!
為累而累

------解決方案--------------------
這樣可能會清楚些
PHP code
class cA{    /**     * Test property for using direct default value     * 使用直接預設值測試屬性     */    protected static $item = 'Foo';        /**     * Test property for using indirect default value     * 使用間接預設值測試屬性     */    protected static $other = 'cA';        public static function method()    {        print __METHOD__ . ' ' . __CLASS__ . '::$item=' . self::$item."\r\n";        print __METHOD__ . ' ' . __CLASS__ . '::$otfer=' . self::$other."\r\n";    }        public static function setOther($val)    {        self::$other = $val; // Set a value in this scope.    }}class cB extends cA{    /**     * Test property with redefined default value     * 重新定義了預設值測試屬性     */    protected static $item = 'Bar';        public static function setOther($val)    {        self::$other = $val;    }}class cC extends cA{    /**     * Test property with redefined default value     * 重新定義了預設值測試屬性     */    protected static $item = 'Tango';        public static function method()    {        print __METHOD__ . ' ' . __CLASS__ . '::$item=' . self::$item."\r\n";        print __METHOD__ . ' ' . __CLASS__ . '::$otfer=' . self::$other."\r\n";    }        /**     * Now we drop redeclaring the setOther() method, use cA with 'self::' just for fun.     */}class cD extends cA{    /**     * Test property with redefined default value     * 重新定義了預設值測試屬性     */    protected static $item = 'Foxtrot';        /**     * Now we drop redeclaring all methods to complete this issue.     * 現在,我們放棄重新聲明的所有方法來完成這個問題     */}cB::setOther('cB'); // It's cB::method()!cB::method(); // It's cA::method()!cC::setOther('cC'); // It's cA::method()!cC::method(); // It's cC::method()!cD::setOther('cD'); // It's cA::method()!cD::method(); // It's cA::method()! 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.