21,886
社区成员
发帖
与我相关
我的任务
分享
<?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);
}
?>
<?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);
}
?>