I've got a small input helper class.
I read a lot that static classes are not the best to use. But I still haven't grasp why I shouldn't use static classes. I'm not that advanced yet, so maybe I will figure it out later on.
The reason I made it static is that it's not an object that's unique every time it's being called in my script.
Is it a good thing that I made the class static?
class Input {
public static function exists($type = 'post') {
switch($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
public static function get($input, $source = 'post') {
if($source == 'post' && isset($_POST[$input])) {
return $_POST[$input];
} else if($source == 'get' && isset($_GET[$input])) {
return $_GET[$input];
}
return false;
}
}
EDIT: Updated code
class Input {
private $_get,
$_post;
public function __construct($get, $post) {
$this->_get = $get;
$this->_post = $post;
}
public function exists($type = 'POST') {
switch($type) {
case 'POST':
return (!empty($this->_post)) ? true : false;
break;
case 'GET':
return (!empty($this->_get)) ? true : false;
break;
default:
return false;
break;
}
}
public function get($input, $source = 'POST') {
if($source == 'POST' && isset($this->_post[$input])) {
return $this->_post[$input];
} elseif($source == 'GET' && isset($this->_get[$input])) {
return $this->_get[$input];
}
throw new Exception('Undefined index: ' . $input);
}
}