I have several classes in the application that I am currently creating, and I want to have one access to some of the other member functions, but I cannot do this.
The first class is called MySQLDB:
class MySQLDB{
public $connection;
function __construct(){
}
function login($username, $password){
}
}
Then I have a Session class:
class Session{
function processlogin($username, $password){
$database->login($username, $password);
}
Then after that I have two class declarations:
$database = new MySQLDB();
$session = new Session();
No matter where I put these statements regarding classes, I still get the same error:
PHP Notice: Undefined variable: database in C:\inetpub\wwwroot\cmu\include\session.php on line 52
PHP Fatal error: Call to a member function login() on a non-object in C:\inetpub\wwwroot\cmu\include\session.php on line 52
I saw some suggestions that would suggest putting a new database object in a Session class declaration, but I want to avoid this because I use the database class in several other places in the code, and I do not want to open multiple database connections.
source
share