I am making a script and am currently working on the database class. I am currently building the Banning
class with two child classes BanSingleIp
and BanIpRange
.
I am puzzled at the moment because I can't seem to think of another way of passing $_POST
variables into the classes without using __construct()
.
This is my Banning
class:
/**
* BANNING CLASS EXTENDS DATABASE CLASS
*/
class Banning extends Database {
}
class BanSingleIp extends Banning {
// Variables for single IP Ban
protected $_S_user_ip;
protected $_S_ban_length;
protected $_S_ban_reason;
protected $_S_ban_start;
protected $_S_ban_end;
/**
* Constructor, assign variables to their values
*/
private function __construct() {
$this->_S_user_ip = ''; // TODO: Replace with $_POST['S_user_ip'];
$this->_S_ban_length = ''; // TODO: Replace with $_POST['S_ban_length'];
$this->_S_ban_reason = ''; // TODO: Replace with $_POST['S_ban_reason'];
$this->_S_ban_start = time();
$this->_S_ban_end = $this->_S_ban_start + $this->_S_ban_length;
}
}
class BanIpRange extends Banning {
protected $_R_user_ip_lowest;
protected $_R_user_ip_highest;
protected $_R_ban_length;
protected $_R_ban_reason;
protected $_R_ban_start;
protected $_R_ban_end;
/**
* Constructor, assign variables to their values
*/
private function __construct() {
// Variables for IP Range Ban
$this->_R_user_ip_lowest = ''; // TODO: Replace with $_POST['R_ip_lowest'];
$this->_R_user_ip_highest = ''; // TODO: Replace with $_POST['R_ip_highest'];
$this->_R_ban_length = ''; // TODO: Replace with $_POST['R_ban_length'];
$this->_R_ban_reason = ''; // TODO: Replace with $_POST['R_ban_reason];
$this->_R_ban_start = time();
$this->_R_ban_end = $this->_R_ban_start + $this->_R_ban_length;
}
}
?>
Because I have two separate banning inserts, a single IP and an IP range I created two child classes with new constructors, however PHP won't allow this. Is there any other way I can do what I am trying to do without the constructors? (I haven't created the $_POST variables yet so that is why they are commented).