【不用eval】可以实现吗?
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 '
';
eval($funstr);
}
}
----------------------------------------
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 已经是自己的了
我感觉到你的思路有点乱了,你能平静下来仔细的描述一下你的需求吗?
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号