Jump to content

[SOLVED] Singleton Patterning Challenge...


mem0ri

Recommended Posts

I'm attempting to run a singleton-pattern on my MySQL Database Class and I'm running into problems referencing over to it...example:

 

On the login page itself:

$user = new User; // loading through the __autoload function and does work
//...IRRELEVANT PHP CODE...
$validate = $user->login($_POST['email'], $_POST['password']);

 

Within the User->login function:

public function login($email, $pass)
{
echo("INSIDE LOGIN");
$sql = MySQL::getinstance();
die("CREATED MYSQL INSTANCE");
        //...ADDITIONAL IRRELEVANT CODE...

 

Within the MySQL::getinstance(); function:

public static function getinstance()
{
if(self::$instance == NULL) self::$instance = new MySQL;
return self::$instance;
}

 

The "echo" and "die" within the User->login() function are just for debugging.  I will always reach the echo, but never reach the die...therefore, the problem is definitely in the MySQL::getinstance() line...

 

...thing is...I can't figure out what's wrong with the structure?

 

The MySQL class and User class are in separate files...but that shouldn't matter with the __autoload function, correct?

Link to comment
https://forums.phpfreaks.com/topic/88093-solved-singleton-patterning-challenge/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.