others - php OOP检查空输入验证的类

我的类


class formvalidation {



 public function check_empty_input($inputs=[]){


 $checked = false;



 foreach($inputs as $valor){


 if(empty($valor)){


 $checked = false;


 break; 


 } else {


 $checked = true;


 }


 }



 if($checked = true){return true;}


 else {return false;}


 }



}



检查post是否为空


 $formvalidation= new formvalidation();



 $inputs = array($_POST['name'],$_POST['email'],$_POST['pass'],$_POST['confirmpass']);


 if($formvalidation->check_empty_input($inputs)) 



时间: 作者:

函数将始终返回= ,另外还应该使用静态函数,在不需要对象来调用此函数时,请尝试以下方法:


<?php



class formvalidation {


 public static function check_empty_input($inputs = []) : bool {


 $everything_filled = true; //start with this supposition


 foreach ($inputs as $valor) {


 if (empty($valor)) {


 $everything_filled = false; // is something is empty, than the supposition is false


 break;


 }


 }


 return $everything_filled; // return the supposition result value


 }


}



$is_my_inputs_filled = formvalidation::check_empty_inputs([


 $_POST['name'],


 $_POST['email'],


 $_POST['pass'],


 $_POST['confirmpass'],


]);



作者:
...