147 php 魔術方法

來源:互聯網
上載者:User
魔術方法

__get , __set (訪問對象屬性不存在時回調)

classObject{protected$array = array();    /**     * [__set 訪問不存在的類對象屬性]     */function__set($key,$value){$this -> array[$key] = $value;    }    function__get($key){        var_dump(__METHOD__);         return$this -> array[$key] ;    }}$Obj = new Object();$Obj  -> title = "Hello World";echo$Obj -> title;

__call (訪問對象方法不存在時回調)

classObject{/**     * [__class 訪問類方法不存在時回調]     * @param  [type] $func  [description]     * @param  [type] $param [description]     * @return [type]        [description]     */function__call($func,$param){        var_dump($func,$param );        echo"magic function \n";    } } $Obj = new Object(); echo$Obj -> test("hello",123); 

__toString(對象轉化為字串)

classLoader{/**     * [__toString 將對象轉化字串]     * @return string [description]     */    function __toString(){        return __CLASS__;    }}$Obj = new Object();echo $Obj;

__invoke(對象做函數)

classLoader{/**     * [__invoke 將對象當作函數調用]     * @param  [type] $param [description]     * @return [type]        [description]     */    function __invoke($param){        var_dump($param);        return"invoke\n";    }}$Obj = new Object();echo $Obj("test");

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介紹了147 php 魔術方法,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.