作者:mkmkunming | 来源:互联网 | 2018-05-07 02:06
无详细内容无?phpclassIndexAction{publicfunctionindex(){echoindex.rn;}publicfunctiontest($year2012,$month2,$day21){echo$year.--------.$month.-----------.$day.rn;}publicfunction_before_index(){echo__FUNCTION__.
无详细内容 无 ?phpclass IndexAction{public function index(){echo 'index'."\r\n";}public function test($year=2012,$mOnth=2,$day=21){ echo $year.'--------'.$month.'-----------'.$day."\r\n";}public function _before_index(){echo __FUNCTION__."\
<无详细内容>
<无>
isPublic()){
$class = new ReflectionClass('IndexAction');
//执行前置方法
if($class->hasMethod('_before_index')){
$beforeMethod = $class->getMethod('_before_index');
if($beforeMethod->isPublic()){
$beforeMethod->invoke(new IndexAction);
}
}
$method->invoke(new IndexAction);
//执行后置方法
if($class->hasMethod('_after_index')){
$beforeMethod = $class->getMethod('_after_index');
if($beforeMethod->isPublic()){
$beforeMethod->invoke(new IndexAction);
}
}
}
//执行带参数的方法
$method = new ReflectionMethod('IndexAction','test');
$params = $method->getParameters();
foreach($params as $param ){
$paramName = $param->getName();
if(isset($_REQUEST[$paramName]))
$args[] = $_REQUEST[$paramName];
elseif($param->isDefaultValueAvailable())
$args[] = $param->getDefaultValue();
}
if(count($args)==$method->getNumberOfParameters())
$method->invokeArgs(new IndexAction,$args);
else
echo 'parameters is not match!';