147 PHP Magic Method

Source: Internet
Author: User
Magic method

__get, __set (callback if the Access object property does not exist)

classObject{protected$arrayarray();    /**     * [__set 访问不存在的类对象属性]     */function__set($key,$value){$thisarray[$key$value;    }    function__get($key){        var_dump(__METHOD__);         return$thisarray[$key] ;    }}$Objnew Object();$Obj  "Hello World";echo$Obj -> title;

__call (callback If the Access object method does not exist)

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";    $Objnewecho$Obj -> test("hello",123

__tostring (object converted to string)

classLoader{/**     * [__toString 将对象转化字符串]     * @return string [description]     */    function __toString(){        return __CLASS__;    new Object();echo $Obj;

__invoke (object do function)

classLoader{/**     * [__invoke 将对象当作函数调用]     * @param  [type] $param [description]     * @return [type]        [description]     */    function __invoke($param){        var_dump($param);        return"invoke\n";    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); }); });

    The above describes the 147 Php magic method, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.