Re: Variable (Class instantiation) collision

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux