<?php
class EchoParam
{
function EchoValue($a,$b)
{
echo "value = ".$a*$b."\n";
}
function EchoValues($a,$b)
{
echo "jjjj";
}
}
class ClsFactory
{
public static function CreateNoCheckModel($classname)
{
return new $classname;
}
}
class Vmware
{
public function doProx($method, $args)
{
$model = ClsFactory::CreateNoCheckModel("EchoParam");
echo call_user_func_array ( array ($model, $method), $args);
}
public function __call($method, $args)
{ var_dump($method);
return $this->doProx($method, $args);
}
}
$a = 1;
$b = 88;
$mwallobj = new Vmware();
$mwallobj->EchoValue($a, $b);
$mwallobj->EchoValues($a, $b);
?>
class EchoParam
{
function EchoValue($a,$b)
{
echo "value = ".$a*$b."\n";
}
function EchoValues($a,$b)
{
echo "jjjj";
}
}
class ClsFactory
{
public static function CreateNoCheckModel($classname)
{
return new $classname;
}
}
class Vmware
{
public function doProx($method, $args)
{
$model = ClsFactory::CreateNoCheckModel("EchoParam");
echo call_user_func_array ( array ($model, $method), $args);
}
public function __call($method, $args)
{ var_dump($method);
return $this->doProx($method, $args);
}
}
$a = 1;
$b = 88;
$mwallobj = new Vmware();
$mwallobj->EchoValue($a, $b);
$mwallobj->EchoValues($a, $b);
?>
这个$method 就是调用的函数名,这就给代理前作判断,而可以代理后就调用modle层的方法,正是因为类Vmware没有这个方法名,而modle层有这个方法名,达到了代理认证的目的。
结果:
[root@vm0000055 ~]# php call_user_func_array.php
string(9) "EchoValue"
value = 88
string(10) "EchoValues"
jjjj
string(9) "EchoValue"
value = 88
string(10) "EchoValues"
jjjj
==========================================
call_user_func_array函数也可以调用类内部的方法的:
Class ClassA
{
function bc($b, $c) {
$bc = $b + $c;
echo $bc;
}
}
call_user_func_array(array('ClassA','bc'), array("111", "222"));
//显示 333
?>
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/1837/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2016-3-8 11:02
评论列表