I
I
Ilya123452021-08-09 13:34:15
PHP
Ilya12345, 2021-08-09 13:34:15

Eval php, why doesn't the second called function work?

Good day.
For a telegram bot, I make responses for messages that contain keywords, and delete them.
It works like this:
If you find a trigger in the message, then it calls the code template associated with the trigger -> eval(stripslashes($code));
Code example called via eval(); ->

$inter = 10; //интервал перед авто удаления сообщения отправленного ботом (сек)
$next = strval(strtotime(date("m/d/Y h:i:s a", time() + $inter)));
$msg_id = (intval($data['message']['message_id'])+1);
$msg_chat_id = $data['message']['chat']['id'];
sendTelegram(
      'sendMessage', 
      array(
        'chat_id' => $msg_chat_id,
        'reply_to_message_id' => $data['message']['message_id'],
        'parse_mode' => 'html',
        'text' => 'текст'
      )
);
call_user_func_array('autoremove_add', array($next,$msg_chat_id,$msg_id));
//autoremove_add($next,$msg_chat_id,$msg_id);

moreover , the sendTelegram call works, but autoremove_add does not. Autoremove_add
function code :
function autoremove_add($time,$chat_id,$message_id){
global $modx;
$modx->log(MODX_LOG_LEVEL_ERROR, "write_message autoremove");
$sql_1 = "INSERT INTO `crontab_telegram` (`id`, `time`, `chat_id`, `message_id`) VALUES (NULL, '$time','$chat_id','$message_id');";
$modx->exec($sql_1);
}

Tell me where to dig.
And yes, eval is evil, but only I edit the fields with the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya12345, 2021-08-10
@Ilya12345

However, the answer was simple, you don’t need to be a bread and shove into eval what can be left in the main code, but from eval pull only a variable, check for its presence, and if it exists, then act.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question