php - Custom class method returns error
迷茫
迷茫 2017-05-24 11:33:57
0
3
436
    $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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
Ty80

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);
世界只因有你

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

仅有的幸福

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template