others - php OOP檢查空輸入驗證的類

143 0

我的類


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



时间: 原作者:

130 4

函數將始終返回= ,另外還應該使用靜態函數,在不需要對象來調用此函數時,請嘗試以下方法:


<?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'],


]);



原作者:
...