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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路