Home  >  Q&A  >  body text

php - Custom class method returns error

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

报错
Warning: Missing argument 1 for Input::post(),
Notice: Undefined variable: key

迷茫迷茫2706 days ago389

reply all(3)I'll reply

  • PHP中文网

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

    Solution:

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

    reply
    0
  • 世界只因有你

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

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

    reply
    0
  • 仅有的幸福

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

    Write less closing curly braces below the Input class }
    In addition, there are no parameters passed in the post method

    reply
    0
  • Cancelreply