[nycphp-talk] Session Objects, Dynamic Parameters
Joseph Crawford
codebowl at gmail.com
Mon Oct 4 20:37:53 EDT 2004
Guys can anyone explain why this is returning odd results?
function &getObject($class, $params=NULL) {
if (!is_array($_SESSION['objects'])) {
$_SESSION['objects'] = array();
}
if (!isset($_SESSION['objects'][$class])) {
if (is_array($params)) {
// this is what is erroring
$args = implode(", ", array_map("paramType", $params));
echo $class.'('.$args.')';
$_SESSION['objects'][$class] =& new $class($args);
} elseif($params != NULL) {
$_SESSION['objects'][$class] =& new $class(paramType($params));
} else {
$_SESSION['objects'][$class] =& new $class;
}
}
return $_SESSION['objects'][$class];
}
function paramType($var) {
if (is_string($var)) {
return "'".$var."'";
} else {
return $var;
}
}
when i call this
$dbParams = array(
'server' => 'localhost',
'database' => 'ipro2',
'username' => 'root',
'password' => '**********'
);
$db = &getObject('Mysql', $dbParams);
$db->connect();
it seems to take this, (which is the actual call in the getObject function
Mysql('localhost', 'database', 'user', '**********')
it seems that
'localhost', 'database', 'user', '**********'
is being taken as one parameter, i am guessing because the getObject
function creates it as one string, my question is how can i get this
to think it is different arguments, i keep getting errors like this
mysql error: Unknown MySQL Server Host ''localhost', 'database',
'user', '**********'' (-1)
--
Joseph Crawford Jr.
Codebowl Solutions
codebowl at gmail.com
802-558-5247
For a GMail account
contact me OFF-LIST
More information about the talk
mailing list