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.