写个例子:
<?php
class Test {
public function phone() {
return '13888888888';
}
private function user($name,$sex) {
return '我是'.$name.',性别'.$sex;
}
}
//调用phone方法
$obj = new Test;
$med = new ReflectionMethod($obj,'phone');
echo $med->invoke($obj);
echo '<hr/>';
//调用user方法
$obj2 = new Test;
$med2 = new ReflectionMethod($obj2,'user');
$med2->setAccessible(true); //设置可访问权限
echo $med2->invokeArgs($obj2,array('lws','男'));