How to create a multi-key dictionary in PHP?

ikmfali

New Member
I use a static function to create a PDO object. It accepts 2 params: a string and an object which contains the connection settings (dns, user, pass). in order to prevent unnecessarily creating duplicate PDO connections with the same name, I tried to create a multi-key dictionary to cache the PDO object in.Here is what I did:\[code\]include_once('IPDOSettings.php');class PDOManager{ private static $connections; // array of connections public static function getConnection(IPDOSettings $settings, $connection_name = 'default') { $dictionary_key = array('name' => $connection_name, 'settings' => $settings); if(!self::$connections[$dictionary_key]) { $DBH = new PDO($settings->getDNS(),$settings->getUser(),$settings->getPass()); self::$connections[$dictionary_key] = $DBH; } return self::$connections[$dictionary_key]; }}\[/code\]However after testing this I get this error Illegal offset type. After looking it up I find out that you cannot use objects or arrays as keys.So is there anyway to do what I am trying to achieve?
 
Back
Top