日期:2014-05-17  浏览次数:20372 次

【不用eval】可以实现吗?
<?php
class Ref{
public $x = '888888888';
public function __construct(){
echo 'father';
}

public function reftest(){
$fun = 'test';
$ss = '$this->y';
$funstr = '$this->'.$fun.'('.$ss.');'; 
echo $funstr ; 
echo '<br/>';
eval($funstr);
}

}
----------------------------------------

<?php
require 'Ref.php';
class SonRef extends Ref {
public $y=array('a','b','c');
public function test($str){
print_r($str); 
}

}

$k = new SonRef();
$k->reftest();

------解决方案--------------------
程序可不会重男轻女。SonRef 和 GirlRef两者都公平的拥有父类的非私有方法。
------解决方案--------------------
$fun = 'test';
$ss = '$this->y';
$funstr = '$this->'.$fun.'('.$ss.');';
eval($funstr);

宜写作
$fun = 'test';
$this->$unn($this->y);

------解决方案--------------------
无论是源于谁,既然你都可以写作 $this->y 那么就说明 y 已经是自己的了

我感觉到你的思路有点乱了,你能平静下来仔细的描述一下你的需求吗?