Home > Backend Development > PHP Tutorial > 【不用eval】可以实现吗?解决方法

【不用eval】可以实现吗?解决方法

WBOY
Release: 2016-06-13 13:32:22
Original
1175 people have browsed it

【不用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 已经是自己的了

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template