I am trying to split the role in OO concept, i created a parent class, child class and created class instance on the starting page.
But the var_dump($this->process_result_sets);
return nothing, could someone explain why?
mail.php
//header('Content-type: application/json');
require_once("../core/core.connection.manager.php");
$responseObj = new ResponseManager();
$json_string = null;
try{
$mssql_instance = new MSSQLManager();
$responseObj->AddResultSets($mssql_instance->GetResultSets());
$json_string = $responseObj->GetJSON();
}catch(Exception $e){
}
core.connection.manager.php
require_once(dirname(__FILE__)."/../config/config.php");
require_once(dirname(__FILE__)."/core.manager.loader.php");
class ResponseManager{
protected $message_list;
protected $error_message_list;
protected $overall_status;
protected $process_result_sets;
function __construct(){
$this->message_list = array();
$this->error_message_list = array();
$this->overall_status = "";
$this->process_result_sets = array();
}
public function AddResultSet($resultSet){
if(empty($resultSet))
return false;
if(isset($resultSet->message) && !empty($resultSet->message))
array_push($this->message_list, $resultSet->message);
if(isset($resultSet->error_message) && !empty($resultSet->error_message))
array_push($this->error_message_list, $resultSet->error_message);
array_push($this->process_result_sets, $resultSet);
print_r($this);
print_r("<hr>");
return true;
}
public function AddResultSets($resultSets){
return array_merge($this->process_result_sets, $resultSets);
}
public function GetResultSets(){
print_r($this->process_result_sets);
print_r("<hr>");
return $this->process_result_sets;
}
public function AddMessage($message){
array_push($this->message_list, $message);
}
public function AddErrorMessage($err_msg){
array_push($this->error_message_list, $err_msg);
}
public function Get(){
return $this->getJSON();
}
public function GetJSON(){
var_dump($this->process_result_sets);
}
}
class ResultSet{
public $message;
public $error_message;
public $status;
public $data;
public $num_rows;
}
db.manager.php
class DatabaseManager{
private $hostname_fyp;
private $database_fyp;
private $username_fyp;
private $password_fyp;
public $responseObj;
function __construct(){
$this->responseObj = new ResponseManager();
try {
$this->hostname_fyp = _DB_HOST;
$this->database_fyp = _DB_NAME;
$this->username_fyp = _DB_USER;
$this->password_fyp = _DB_PASS;
$hostname_fyp = $this->hostname_fyp;
$database_fyp = $this->database_fyp;
$username_fyp = $this->username_fyp;
$password_fyp = $this->password_fyp;
//$this->responseObj->AddResultSet((object) array('message' => 'DatabaseManager __construct.'));
}catch (Exception $e) {
//$this->responseObj->AddResultSet((object) array('error_message' => $e->getMessage()));
}catch (PDOException $e) {
//$this->responseObj->AddResultSet((object) array('error_message' => $e->getMessage()));
}
$this->_Initialize();
}
function _Initialize(){
//$this->responseObj->AddResultSet((object) array('message' => 'Initialized in DatabaseManager()'));
$this->Initialize();
}
function Initialize(){ }
function GetResultSets(){
return $this->responseObj->GetResultSets();
}
function CloseConnection(){
//$this->responseObj->AddResultSet((object) array('message' => 'close db connection.'));
}
function __destruct() {
$this->CloseConnection();
}
}
db.mssql.manager.php
class MSSQLManager extends DatabaseManager {
function __construct(){
parent::__construct();
$resultSet = new ResultSet();
$resultSet->message = "MSSQLManager __construct.";
$this->responseObj->AddResultSet($resultSet);
}
function Initialize(){
//$this->responseObj->AddResultSet((object) array('message' => 'Initialized in MSSQLManager()'));
}
function CloseConnection(){
//$this->responseObj->AddResultSet((object) array('message' => 'close mssql connection.'));
}
}
the expected result is providing the "MSSQLManager __construct." message. in actual result, the message lost in 3rd call.
//add value from child class
ResponseManager Object ( [message_list:protected] => Array ( [0] => MSSQLManager __construct. ) [error_message_list:protected] => Array ( ) [overall_status:protected] => [process_result_sets:protected] => Array ( [0] => ResultSet Object ( [message] => MSSQLManager __construct. [error_message] => [status] => [data] => [num_rows] => ) ) )
//get value from parent class
Array ( [0] => ResultSet Object ( [message] => MSSQLManager __construct. [error_message] => [status] => [data] => [num_rows] => ) )
//get value by object instance
array(0) { }