<?php
/**
* A counter class
*/
class Counter{
private $ss = 'dd';
private $dd = 'ss';
public $o = 'o'; public function getSs(){
return $this -> ss;
}
public function getO(){
return $this -> o;
}
public function getDd(){
return $this -> dd;
}
} $ct = new Counter();
echo invoke($ct, getMethod('ss')); //输出dd
function getMethod($fieldName){
return 'get' . ucfirst($fieldName);
}
function invoke($obj, $methodName){
/*$reflector = new ReflectionObject($obj);
$method = $reflector -> getMethod($methodName);
return $method -> invoke(null); //反射调用有问题 */
return $obj ->$methodName(null);
}
?>
解决方案 »
- php4升级到php5中遇到的问题
- php socket 字节控制
- php如何配置授权远程调用函数?
- 请教在zend studio for eclipse怎样使用zend studio的快捷键,或者自定义快捷键.
- 求一MySQL语句或解决问题思路
- 紧急求助:如何把数据库的二进制数据流保存成服务器的文件?二进制流有可能是txt、wav或者zip格式
- 奇怪,E_ALL&~NOTICE并不现实include文件错误信息?
- 想实现一个抓取,遇到了防抓高手,来CSDN请教,源码贴出来了,大家可以参考
- 关于smarty的templates设置问题
- PHP 版变成招聘频道了~!!
- 看CSDN的的迷茫
- 怎么把指定的网页转化成pdf格式化
<?php
/**
* A counter class
*/
class Counter{
private $ss = 'dd';
private $dd = 'ss';
public $o = 'o'; public function getSs(){
return $this -> ss;
}
public function getO(){
return $this -> o;
}
public function getDd(){
return $this -> dd;
}
} $ct = new Counter();
echo invoke($ct, getMethod('ss')); //输出dd
function getMethod($fieldName){
return 'get' . ucfirst($fieldName);
}
function invoke($obj, $methodName){
/*$reflector = new ReflectionObject($obj);
$method = $reflector -> getMethod($methodName);
return $method -> invoke(null); //反射调用有问题 */
return $obj ->$methodName(null);
}
?>
原来是类似JS的函数指针来用不过,PHP参考手册上能够用ReflectionMethod的invoke方法来调用
还是不理解。手册上传的用的是ReflectionClass,我用ReflectionObject而已