use*_*796 -1 php forms arrays oop foreach
我有一个包含此代码的表单,因此我可以在检查类中的字段时回显错误:
<?php if( isset($_POST['send'])){     
        $new_user = new Register();
        $new_user->check_required_fields($_POST);
        $new_user->display_errors();
    } 
?>
而且课程是:
<?php
    class Register extends Database
    {
        public $fname;
        public $lname;
        public $uname;
        public $email;
        public $pass1;
        public $pass2;
        public $year;
        public $month;
        public $day;
        public $required_array;
        public $error;
        public $errors = array();
        public function check_required_fields($required_array)
        {
             if(in_array('', $required_array)) {
                 $errors[] = "One or more fields are missing";
                 //var_dump($errors);
             }
             else
             { 
                 $errors[] = "All fields are ok";
                 $this->fname = $required_array['fname'];
                 $this->lname = $required_array['lname'];
                 $this->uname = $required_array['lname'];
                 $this->email = $required_array['email'];
                 $this->pass1 = $required_array['pass1'];
                 $this->pass2 = $required_array['pass2'];
                 $this->year = $required_array['year'];
                 $this->month = $required_array['month'];
                 $this->day = $required_array['day'];
             }
         }
         public function display_errors ($errors)
         {
             foreach ($errors as $error){
                 echo $error;
             }
         }
由于某种原因,它不会显示$ errors数组,我不知道为什么?我会很高兴得到任何帮助,谢谢.