I'm trying to call a function from one class within another class and I just can't seem to get it to work. Here's some pseudo code. Note that each class is in a separate file.
// File1.php
class Database {
function Database() {
// Init code here
}
function OpenDatabase() {
// open the database
}
}
$database = new Database();
// File2.php
require("File1.php");
class Categories {
function Categories() {
//Init code here
}
function GetAllCategories() {
global $database;
if ( $database->OpenDatabase() )
//Get the categories in the database
else
// die
}
}
When I try to run this code, I get the error: "Fatal error: Call to a member function on a non-object" and it references the "$database->OpenDatabase()" line.
So apparently the $database variable doesn't contain the class information. Would this have anything to do with 'register_globals' being off? I've been pulling my hair out for hours!
Thanks in advance for any help!