I used the instructions in this post: http://stackoverflow.com/questions/475569/get-all-instances-of-a-class-in-php to keep all instances of a class in an array. But when I change an object inside of the array, it doesn't change the "original".
class Pane {
protected $data;
public $name;
public static $instances = array();
public function __construct($name) {
$this->name = $name;
self::$instances[] = $this;
}
public static function load_from_files(Pane &$pane) {
$file_name = "data/system_{$pane->name}.data";
if (file_exists($file_name))
$pane = unserialize(file_get_contents($file_name));
}
}
$panel = new Pane; // Define three instances
$pane2 = new Pane;
$pane3 = new Pane;
foreach (Pane::$instances as &$pane) // each instance loads.
Pane::load_from_files($pane);
print_r($pane); // Is changed
print_r(Pane::$instances); // Is too.
print_r($pane1); // Is not.
Am I missing something? Aren't all the objects different references to the same instances kept in the class's static array?