douyun3022 2014-11-21 20:25
浏览 90
已采纳

致命错误:函数名称必须是字符串

I ran into a problem when trying to code along to this video tutorial on Beginner level PHP. I am having problems getting it to work for me. I get this error that states the problem is in line 44 of my code in the mailprocess.php file when I try loading the project in the browser. Line 44 of my code that this error is pertaining to is the beginning of an if statement: if (isset($$item) && !$empty($$item))

But when the instructor doing the video tutorial does this same thing, it works fine for him. So I don't understand why it's not working for me. I am also having problems getting the hang of getting my copy/pasted code to format correctly in the code block format tool here in order to post it, so please bear with me if it's not aligned perfectly as I am new and really struggling trying to learn and I am finding PHP to be rather difficult. Any help at all to get this to work for me would be greatly appreciated.

Here is the browser output of the error I am getting: enter image description here

Here is my mailprocess.php file and code:

    <?php
        $suspect = false;
        $pattern = '/Content-Type:|Bcc:|Cc:/i'; //Perl compatible reg-x to filter     
        $empty = false;

        function isSupect($val, $pattern, &$suspect) {
          if (is_array($val)) {
            foreach ($val as $item) {
              isSuspect($item, $pattern, $suspect);
            }
          }else {
            if (preg_match($pattern, $val)) {
            $suspect = true;
          }
        }
        isSuspect($_POST, $pattern, $suspect);
       }



       if (!$suspect) {
         foreach ($_POST as $key => $value) {
           $temp = is_array($value) ? $value : trim($value); //removes white space
           if (empty($temp) && in_array($key, $required)) {
             $missing[] = $key;
              $$key = '';
           } elseif (in_array($key, $expected)) {
        $$key = $temp;
       }
      }
     }

     if (!$suspect && !$empty['$email']) {
        $validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
           if ($validemail) {
              $headers .= "
Reply-to: $validemail";
           } else {
               $errors['email'] = true;
        }
      }

    if (!$suspect && !$missing && !$errors){
        $message = ' ';
        foreach ($expected as $item) {
           if (isset($$item) && !$empty($$item)){
              $val = $$item;
            } else {
                $val = 'Not selected';
            }
            if (is_array($val)){
                $val = implode(', ', $val);
            }
        $item = str_replace(array('_', '-'), '', $item);
        $message .= ucfirst($item) . ": $val

";
      }
      $message = wordwrap($message, 70);
      $mailSent = true;
    }

And here is what the instructor has in his code:enter image description here

  • 写回答

2条回答 默认 最新

  • drruhc4944 2014-11-21 20:32
    关注
    if (isset($$item) && !$empty($$item))
    

    should be

    if (isset($$item) && !empty($$item))
    

    Just a typo on the !$empty().

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记