eval()代码中的意外$ end [英] Unexpected $end in eval()'d code

查看:76
本文介绍了eval()代码中的意外$ end的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想问这样一个具体的问题,但是我遇到了一个我不知道的错误.这是一项按小时运行的cron作业.我正在创建一个任务数组,每个任务都有一个日期检查,应该由eval()完成.

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.

$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];
    }
}

由于某些原因,eval()行给了我这个错误. 请注意,两个任务都遇到此错误.

For some reason the eval() line is giving me this error. Note that I am getting this error for both tasks.

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.

推荐答案

eval仅接受语句,不接受表达式.您需要使用以下方法转换测试:

eval only accepts statements, not expressions. You need to convert your tests with:

if (eval("return $task[0];")) {

这篇关于eval()代码中的意外$ end的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆