07-10-2008, 02:19 PM
|
#3 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Oy vey, why is it everytime I think I actually have an interesting question, the answer was staring me in the face the whole time? You hit the nail on the head, though I don't need to use any magic functions at all.
PHP Code:
class pointer {
public function connect () { echo 'connected!'; }
}
class factory {
static public $inst; public $pPointer;
static public function getInstance ($child) { self::$inst = new $child; self::$inst->pPointer = new pointer; return self::$inst; }
protected function _point () { $this->pPointer->connect(); }
}
class child extends factory {
public function works () { $this->_point(); }
}
$pTester = factory::getInstance('child'); $pTester->works();
Sometimes my own 'logic' is the most blinding. My getInstance method was doing what it was supposed to in a specific order: initialize values, determine what the factory is generating, generate new object. The static method did everything I thought it could, then pumped out the child like a baby with it's return statement. The answer was in reversing the steps... generate the object, initialize the values directly in the object, then return the object.
Okay, back to work...
-m
|
|
|
|