I hate to ask such a specific question, but I'm getting an error I can't figure out. This is in a cron job which runs on the hour. I'm creating an array of tasks, each of which has a date check which is supposed to be eval()'d.
我讨厌问这么具体的问题,但我犯了一个我搞不懂的错误。这是一项正常的工作。我正在创建一个任务数组,每个任务都有一个日期检查,它应该是eval()'d。
$todo = array();
$todo[] = array( "date('z')%3 == 0", "Task 1" );
$todo[] = array( "date('N') == 1", "Task 2" );
foreach( $todo as $task )
{
if( eval($task[0]) ) {
echo $task[1];
}
}
For some reason the eval() line is giving me this error. Note that I am getting this error for both tasks.
出于某种原因,eval()行给了我这个错误。注意,我在这两个任务中都得到了这个错误。
Parse error: syntax error, unexpected $end in /file.php(21) : eval()'d code on line 1
Any suggestions? I tried searching for this but couldn't find anything. Thank you.
有什么建议吗?我试着找这个,但什么也没找到。谢谢你!
1 个解决方案
#1
21
eval
only accepts statements, not expressions. You need to convert your tests with:
eval只接受语句,不接受表达式。您需要将您的测试转换为:
if (eval("return $task[0];")) {
#1
21
eval
only accepts statements, not expressions. You need to convert your tests with:
eval只接受语句,不接受表达式。您需要将您的测试转换为:
if (eval("return $task[0];")) {