Hi guys,
I am trying to call a class function from another class function but when calling global $hcdb; it loads as NULL. I read some time ago about having to declare it as a global but think it was only for variables. Any ideas? Sounds like quite a basic thing...
Stripped code of the files below:
main.php (the one that loads first)
require_once(HC_PATH_INTERNAL."/includes/database.php");
require_once(HC_PATH_INTERNAL."/includes/functions.php");
$hc->format();
database.php
class HcDatabase {
function checknicename() { return 1; }
}
$hcdb = new HcDatabase;
functions.php
class HcFunctions {
function format() {
global $hcdb;
var_dump($hcdb); // returns NULL
$hcdb->checknicename();
}
}
$hc = new HcFunctions;