i have two classes Session and SupplierSession. SupplierSession is supposed to inherit from Session. how do i ensure that the session_start() in the __construct() method of Session does not get called in SupplierSession. here are the class definitions.
session.php
<?php
class Session {
private $loggedIn = false;
public $userID;
public function __construct() {
session_start();
$this->checkLogin();
}
public function isLoggedIn() {
return $this->loggedIn;
}
public function login( $user ) {
if ( $user ) {
$this->userID = $_SESSION['userID'] = $user->userID;
$this->loggedIn = true;
}
}
public function logout() {
unset( $this->userID );
unset( $_SESSION['userID'] );
$this->loggedIn = false;
}
private function checkLogin() {
if ( isset( $_SESSION['userID'] ) ) {
$this->userID = $_SESSION['userID'];
$this->loggedIn = true;
} else {
unset( $this->userID );
$this->loggedIn = false;
}
}
}
$session = new Session();
?>
suppliersession.php
<?php
class SupplierSession extends Session {
private $loggedIn = false;
public $supplierID;
public function __construct() {
session_start();
$this->checkLogin();
}
public function isLoggedIn() {
return $this->loggedIn;
}
public function login( $supplier ) {
if ( $supplier ) {
$this->supplierID = $_SESSION['supplierID'] = $supplier->supplierID;
$this->loggedIn = true;
}
}
public function logout() {
unset( $this->supplierID );
unset( $_SESSION['supplierID'] );
$this->loggedIn = false;
}
private function checkLogin() {
if ( isset( $_SESSION['supplierID'] ) ) {
$this->supplierID = $_SESSION['supplierID'];
$this->loggedIn = true;
} else {
unset( $this->supplierID );
$this->loggedIn = false;
}
}
}
$supplierSession = new SupplierSession();
?>