Heim  >  Fragen und Antworten  >  Hauptteil

php – Benutzerdefinierte Klassenmethode gibt einen Fehler zurück

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

报错
Warnung: Fehlendes Argument 1 für Input::post(),
Hinweis: Undefinierte Variable: Schlüssel

迷茫迷茫2706 Tage vor386

Antworte allen(3)Ich werde antworten

  • 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);

    Antwort
    0
  • 世界只因有你

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

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

    Antwort
    0
  • 仅有的幸福

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

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

    Antwort
    0
  • StornierenAntwort