当前位置:Gxlcms > PHP教程 > 147php魔术方法

147php魔术方法

时间:2021-07-01 10:21:17 帮助过:31人阅读

魔术方法


__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教程有兴趣的朋友有所帮助。

  • 人气教程排行