首页  >  问答  >  正文

php - 自定义类方法返回错误

雷雷 雷雷

报错
警告:Input::post()缺少参数1,
注意:未定义的变量:key

迷茫迷茫2706 天前388

全部回复(3)我来回复

  • PHP中文网

    PHP中文网2017-05-24 11:35:57

    解决:

    class Input{
      public function post($key){
            if(isset($_POST[$key])){
                $val=$_POST[$key];
                return $val;
            }
            
      }
    
    
    $input=new Input();
    $upSet=$input->post("demo");
    var_dump($upSet);

    回复
    0
  • 世界只因有你

    世界只因有你2017-05-24 11:35:57

    function post($key = 'default'){}

    回复
    0
  • 仅有的幸福

    仅有的幸福2017-05-24 11:35:57

    Input类下面少写个闭合的花括号 }
    另外post方法里没有传参

    回复
    0
  • 取消回复