class queue {
public static $data = array();
public static function add(&$obj) {
if(isset(self::$data[$obj->var])) {
$obj = self::$data[$obj->var];
}
self::$data[$obj->var] = $obj;
}
public static function process() {
$obj = self::$data['a'];
$obj->set('updated');
}
}
class object {
public $var;
public function __construct($v) {
$this->var = $v;
}
public function set($v) {
$this->var = $v;
}
public function queue() {
queue::add($this);
}
}
$a = new Object('a');
$b = new Object('a');
$a->queue();
$b->queue();
queue::process();
echo $a->var . "<br />";
echo $b->var . "<br />";
Sorry if this is slightly confusing to follow. My output goal would be "updated" for both objects. Since object A and B had the same idea, when they were queued, object B would reference object A. This works fine if I add the objects to queue:add() from outside the class. Once I try to do the same thing within the class, it fails. Any idea?