static variable refering , any issues, no idea

Just a scribble :

For a single db server this served:

function getInstance()
{
global $sqllog;
static $instance;
if (isset($instance)) {
return $instance;
}else{
$instance = new DBHandler();
$sqllog->debug(“Creating a new DBHandler instance”);
return $instance;
}
}

Actually , this function of mine , I modified to suit multi DB server on the instantiation to have any conn. object to a server as

function getInstance( $whichServer )
{
global $sqllog;
$instance = $whichServer.’instance’;
static $$instance;
if (isset($$instance)) {
return $$instance;
}else{
$$instance = new DBHandler( $whichServer );
$sqllog->debug(“Creating a new DBHandler instance”);
return $$instance;
}
}

But above, after some review with my friend, we narrowed a issue with static $$instance causing error. No idea at this moment but seems like a bit of change gets the need still fine as below:

function getInstance( $whichServer )
{
global $sqllog;
static $instance;
$$instance = $whichServer.’instance’;
if (isset($instance) && is_object($$instance))
{
return $$instance;
}
else
{
$$instance = new DBHandler( $whichServer );
$sqllog->debug(“Creating a new DBHandler instance”);
return $$instance;
}
}

Third eye, is my buddy pair ANil and courtesy do mentioned to him. 🙂 Please feel free to comment your thoughts for it might help me understand better.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: