Hallo,
ich habe ein Problem mit einem Konstrukt folgender Art:
<?php
class A
{
var $id = NULL;
function A($id)
{
$this->id = $id;
}
function set_id($id)
{
$this->id = $id;
}
function get_id()
{
return $this->id;
}
}
class B
{
var $my_a = NULL;
function B($a)
{
$this->my_a = $a;
}
function show_my_a_id()
{
echo($this->my_a->get_id() ."<br>");
}
}
$a = new A("1");
$b = new B($a);
$b->show_my_a_id();
$a->set_id("2");
$b->show_my_a_id();
?>
Wieso wird der Wert von $a nicht auch in der Klasse $b aktualisiert???
Die Variable $this->my_a in der Klasse B zeigt doch auf $a!
Das heisst, wenn ich a direkt verändere, müssten auch alle verweise auf a den neuen Wert (hier:2) anzeigen.
So was ist doch enorm wichtig für oop-programmierung!?
Oder steh ich auf dem Schlauch?