<?php /** * Created by PhpStorm. * User: machenike * Date: 2016/9/8 * Time: 10:42 */ header("content-type:text/html;charset=utf-8"); class human{ /* * 魔术方法__call $method 获得方法名 $arg 获得方法的参数集合 * 当调用一个未定义的静态方法时自动调__callStatic方法 */ public function __call($method,$arg){ echo '你想调用我不存在的方法',$method,'方法<br/>'; echo '还传了一个参数<br/>'; echo print_r($arg),'<br/>'; } //魔术方法__callStatic 当调用一个未定义的静态方法时自动调__callStatic方法 public static function __callStatic($method,$arg){ echo '你想调用我不存在的',$method,'静态方法<br/>'; echo '还传了一个参数<br/>'; echo print_r($arg),'<br/>'; } } $a=new human(); $a->ca("1231231");// 当调用一个未定义的方法时自动调__call方法 //$a::ca('哈哈');// 当调用一个未定义的静态方法时自动调__callStatic方法
魔术方法(__call/__callstatic)
最新推荐文章于 2023-09-20 18:44:57 发布