Registry problem
Posted: Mon Jul 17, 2006 10:44 am
I can't get my registry to work properly...
If I call $error->push, it is a different instance than if I call $registry->instances['error']->push... shouldn't they be the same since I am calling the objects by reference in my registry?
Code: Select all
class Registry{
var $instances;
function register($name, &$object) {
$this->instances[$name] = $object;
}
function get($name) {
return $this->instances[$name];
}
}
class Error{
var $errors = array();
function push($error){
$this->errors[] = $error;
}
}
class MysqlConnect{
function MysqlConnect($host, $user, $pass, &$registry){
$this->host = !empty($host) ? $host : false;
$this->user = !empty($user) ? $user : false;
$this->pass = !empty($pass) ? $pass : false;
$this->error = $registry->get('error');
if(@mysql_pconnect($host, $user, $pass)){
echo "Connected!";
}
else{
$this->error->push(mysql_error());
}
$this->error->push("hi");
}
}
$registry = new Registry;
$error = new Error;
$registry->register('error', $error);
if(!empty($error->errors) && $GLOBALS['debug'] > 0) print_r($error->errors);