-1

これは私のコードです。

$script = $row['script']; 

   // $row is from database and the $row['script'] is exeactly the same with $script commented below.
  // $script ="global \$timedate;\$target =\$timedate->now();return \$target;";

return eval($script);

$script のコメントを外すと、正しく実行されます。ただし、$script にコメントを付けて $row['script'] から値をロードすると、eval で以下のエラーが発生します。

 [12-May-2012 22:09:25 UTC] PHP Parse error:  syntax error, unexpected $end in C:\Users\iopen\Documents\IOPEN\Project\Clients\sugarcrm\hfcrmlocal\custom\modules\iopenwf\model\IOpenAction.php(56) : eval()'d code on line 3

何か案が?

4

2 に答える 2

1

eval非常に悪い考えを使用しないでください。

stripslashes実験目的で、ほとんどのスラッシュの問題を削除するために使用できます

class Test {
    function now() {
        return time ();
    }
}

$timedate = new Test ();
$script = "global \$timedate;\$target =\$timedate->now();return \$target;";
$script = stripslashes ( $script );
var_dump ( eval ( $script ) );
于 2012-05-12T22:33:58.200 に答える
0

スクリプトの関数を作成してみてください。後で編集しやすくなり、全体像がよくなります。ご覧のとおり、eval(); を削除します。関数。今、それは仕事をします。なぜ eval() が必要なのかわかりませんが、以下のスクリプトでは eval() がありません。必要です。

<?php
   function getScript() {
      $script = 1;  
      // $row is from database and the $row['script'] is exeactly the same with $script commented below.
      // $script ="global \$timedate;\$target =\$timedate->now();return \$target;";
      return $script;
      }
   $scriptNo = getScript();
   echo $scriptNo;
?>
于 2012-05-12T22:42:48.390 に答える