dougu0824 2012-09-21 14:40
浏览 62
已采纳

另一个eval()受害者

Some code uses eval() to execute code stored in an array like this:

// $oOwner is an object
$strId = "abc";
$strClass = "someClass";
$aParams = array('a' => 'atext', 'b' => 'btext');

$this->menu = array(
"Entry 1" => ' openForm(\$oOwner,\$strId,\$strClass,\$aParams); ',
// ...
);

The values of the array's keys will be given directly into an eval() function.

Now I get an error: Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING ... eval()'d code on line 1

What is the problem?


EDIT:

Loop through the array and eval() the values:

eval( $this->menu[$param[0]] );

EDIT 2:

Now: "Entry 1" => " openForm(\$this->owner,\$strId,\$strClass,\$aParams); "

Using double quotes "..." leads to PHP Notice: Undefined variable: strId in ... : eval()'d code on line 1. Also for the other variables.

`

  • 写回答

3条回答 默认 最新

  • douzhengzuo7283 2012-09-25 09:01
    关注

    The way I tried always led to errors and I came up with the idea of putting the array in there as a string via var_export().

    There are 2 attempts posted here: Store array in a string to eval() later

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题