Greetings,
I just started using OOP. Maybe I do not understand this functionnality of PHP yet. Here is the problem I have. See the code below.
define('APP_BASE', dirname(__FILE__) . '../' );
class CAMPix {
var $_redirstatus = NULL;
var $_assignments = NULL;
var $_status = NULL;
function CAMPix() {
// Get current redirections status
if (file_exists(APP_BASE . '/config/current/redirections.status')) {
if (!is_readable(APP_BASE . '/config/current/redirections.status')) {
die ("Cannot read required file '/config/current/redirections.status'.");
} else {
$_redirections = @shell_exec('/bin/cat ' . APP_BASE . '/config/current/redirections.status');
}
} else {
die ("Required '/config/current/redirections.status' does not exist.");
}
// Parse current redirection status
if (!preg_match_all("(.*:.*)", $_redirections, $redir)) {
die ("No redirections set.");
} else {
$_redirections = $redir[0];
$parsed_redir = array();
foreach ($_redirections as $redir) {
$r = explode(":", $redir);
array_push($parsed_redir, array('from_cluster' => $r[0], 'to_cluster' => $r[1]));
}
$_status->redirections = $parsed_redir;
}
// Get current services assignments
if (file_exists(APP_BASE . '/config/current/services.assignments')) {
if (!is_readable(APP_BASE . '/config/current/services.assignments')) {
die ("Cannot read required file '/config/current/services.assignments'.");
} else {
$_assignments = @shell_exec('/bin/cat ' . APP_BASE . '/config/current/services.assignments');
}
} else {
die ("Required '/config/current/services.assignments' does not exist.");
}
// Parse current services assignments
if (!preg_match_all("(.*:.*)", $_assignments, $assign)) {
die ("File '/config/current/services.assignments' is empty or format is invalid.");
} else {
$_assignments = $assign[0];
// print_r($_assignments);
$parsed_assign = array();
foreach ($_assignments as $assign) {
$r = explode(":", $assign);
array_push($parsed_assign, array('cluster' => $r[0], 'services' => $r[1]));
}
$_status->assignments = $parsed_assign;
}
// TODO
// Function to get current status of services + clusters
return $_status;
}
// some other functions ...
}
Now, in the constructor of CAMPix, if I print the $_status object, it outputs fine. But the problem lies when I create a new class instance ... See this code ;
define('APP_BASE', dirname(__FILE__));
include_once APP_BASE . '/lib/campix.class.php';
$status = new CAMPix();
print_r($status);
This call outputs an empty Object
campix Object
(
)
How come ? ! 😕