与eval()
有问题。我被迫将字符串存储在稍后执行的数组中。将数组存储到eval()以后的字符串中
现在,在字符串中存储字符串是没有问题的。但是,如何在那里存储数组?由于我将无法访问该变量,因此我希望将该数组直接存储到此字符串中。
看到这个代码:
// ----------------------
// -- class A
$strId = 'id_1234';
$strClass = 'classname';
$arParams = array('pluginid' => 'monitor', 'title' => 'Monitor', ...);
$strClone = 'openForm(desktop(),"'.$strId.'","'.$strClass.'",'.$arParams.');';
$this->menu = array("clone" => $strClone, ...);
// ----------------------
// -- class B
// loop through $this->menu, then..
{
eval($this->menu[$item]);
}
// ----------------------
// -- class C
function openForm($owner, $id, $class, $params)
{
...
}
一切完美除阵列$arParams
。
There is an error: PHP Parse error: syntax error, unexpected ')', expecting '(' in ... (441) : eval()'d code on line 1
问题是什么? 我可以在没有serialize()
的情况下这样做吗?
编辑:
我已成立了是怎么回事的表示。如果您收到此运行,那么它是固定的:
$ar = array('a' => 'value1', 'b' => 'value2');
$str = "something";
$run = " a('".$str."', \$ar); "; // this line may be changed
// this is done to represent the loss of the variables in another class
unset($ar);
unset($str);
// $run is kept
eval($run);
function a($str, $ar) {
echo "\$str=" . $str . "<br>";
echo "\$ar['a']=" . $ar['a'] . "<br>";
echo "\$ar['b']=" . $ar['b'] . "<br>";
}
几乎肯定会有一种方法来解决您的问题,而不使用eval()。你能否发表更多关于你认为你需要它的原因? – cmbuckley
我们使用那个奇怪的“框架”,只有在绝对必要的时候,才能改变它。没有它我也能解决它。 – Patrick
那我该怎么做'eval()'的方式? – Patrick