<?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();
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();
}请问:GirlRef 和 SonRef 不会共享一个Ref吧? 是的话我写的东西就全完蛋了。
$ss = '$this->y';
$funstr = '$this->'.$fun.'('.$ss.');';
eval($funstr);宜写作
$fun = 'test';
$this->$unn($this->y);
都是配置信息,否则我也会直接调用了。
没看懂。5555 。 我是想要:sonRef,对象有一个自己的Ref,GirlRef对象有另外一个Ref啊。
$param2 = '$this->z';因为字符串:'$this->y'是动态生成的,我并不知道它是y.
所以才会出现拼接代码:如下
$fun = 'test';
$ss = '$this->y'; //这个$ss的值是传入的。
$funstr = '$this->'.$fun.'('.$ss.');';
eval($funstr);