私は他の多くのクラスを作成するクラスを持っています。
親クラスにリンクを作成するために、変数の代わりに参照を使用することをお勧めしますか?
このスタイルを使用してメモリを保持できますか、それとも問題ではありませんか?
そして、これは同じ(1つの)クラスですか?親クラスの値を変更すると、他のすべてのクラスに新しい名前が表示されますか?
class item implements Iterator {
private $name = 'Awesome name';
private $data = Array();
function __construct () {
for ($i=0; $i<10; $i++) {
$this->data[$i] = new type(&$this);
}
}
public function rewind() { reset($this->data); }
public function current() { return current($this->data); }
...
}
class type {
private $parent = false;
function __construct ($a) {
$this->parent =&$a;
}
function do () {
echo $this->parent->name . "\n";
}
}
$i = new item ();
foreach ($i as $t) {
$t->do();
}