我有以下类:
class Decode {
public $code;
public $codeStore;
public $store;
public $varName;
public $storeNew = array();
public $storeNew = array();
public function __construct($code) {
$this->code = $code;
$this->codeStore = $code;
$this->varName = substr($this->code, 0, 30);
$this->varName = str_replace("var ", "", $this->varName);
$this->varName = substr($this->varName, 0, strpos($this->varName, "=[\""));
}
public function chrToVar() {
// The line below is line 38
$this->code = preg_replace_callback('/'.$this->varName.'\[([0-9]+)\]/', function($matches) { return $this->storeNew[$matches[1]]; }, $this->code);
}
}
$script = new Decode('stuff');
$script->chrToVar();
当我运行这段代码,我得到以下错误:
致命错误:使用$这在不在线38 /var/www/programs/decode.php对象上下文
这究竟是为什么? 我想它是与已在该函数的参数preg_replace_callback
,但我不知道如何解决它。