Re: Variable (Class instantiation) collision
| From: | David Harkness | Date: | Tue, 05 Oct 2010 21:45:33 +0000 |
| Subject: | Re: Variable (Class instantiation) collision | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308499@lists.php.net to get a copy of this message | ||
If you have total control over application A which contains the bridge code,
the easiest is to change it to use a different global variable, $dbA. This
must not be doable or you wouldn't have asked.
If you have control over the bridge code, and it alone calls A and B, then
you could swap the $db variables between calls:
$db = null;
$dbA = null;
$dbB = null;
function copyPersons() {
useA();
$persons = loadPersonsFromA();
useB();
savePersonsInB($persons);
}
function connect() {
global $db, $dbA, $dbB;
connectToA();
$dbA = $db;
unset($db);
connectToB();
$dbB = $db;
unset($db);
}
function useA() {
global $db, $dbA;
$db = $dbA;
}
function useB() {
global $db, $dbB;
$db = $dbB;
}
This is the simplest implementation. You could get trickier by tracking
which system is in use and only swapping them as-needed, writing a facade
around the APIs to A and B. It's ugly, but it works.
David