fields = array(); } public function add_num($value) { $this->add_num = $value; } public function setclass($value) { $this->class = $value; } public function set_num($value) { $this->set_num = $value; } public function getFields() { return $this->fields; } public function buildFields() { try { $this->check_parameter(); } catch (Exception $e) { echo $e; } $keys = array( 'add_num', 'class', 'set_num' ); foreach ($keys as $key) { if (isset($this->$key)) { $this->fields[$key] = $this->$key; } } } private function check_parameter() { if (($this->add_num) && (gettype($this->add_num) != "integer")) { throw new Exception("type of add_num is wrong."); } if (is_int($this->add_num) && ($this->add_num < 1 || $this->add_num > 100)) { throw new Exception("add_num should locate between 0 and 100"); } if (($this->set_num) && (gettype($this->set_num) != "integer")) { throw new Exception("type of set_num is wrong."); } if (is_int($this->set_num) && ($this->set_num < 1 || $this->set_num > 100)) { throw new Exception("set_num should locate between 0 and 100"); } } }