Jeg har et problem med Objecter, jeg kan ikke gemmenløbe et kædet array. Lad mig illustrer.
I got this problem with objekts. If I makes a list of objekt, where the first has the pointer to the next objekt in the list. Like this program down here.
class a {
var $nummer;
var $next; // Dette peger på det næste element i listen.
function a ($nr,$next) {
$this->next = $next;
$this->nummer = $nr;
}
function get_next() { return $this->next; }
function get_nummer() { return $this->nummer; }
function set_nummer($nr) { $nummer = $nr; }
}
// The class is made
for($i=0;$i < 10;$i++) // I put some data in the list
$list = new a($i,$list); // The value list holds the first element in the list
// Here is the problem
$list_2 = &$list; // This will make $list_2 point to same place as $list. Right ??
$list_3 = $list; // This makes a complet copy of $list to $list_3.
while($list_3) { // This will run true the list of copy objekt, No problem :-)
echo "|list_3|".$list_3->get_nummer()."|<br>\n";
$list_3 = $list_3->get_next();
}
while($list_2) { // This will run true the shared list.
echo "|list_2|".$list_2->get_nummer()."|<br>\n";
$list_2 = $list_2->get_next();
}
while($list) { // This should run true the shared list too.
echo "|list|".$list->get_nummer()."|<br>\n";
$list = $list->get_next();
}
The last 'while' will not but anything out WHY ??
$list and $list_2 gets the same start pointer, but why do $list move when I move the pointer to $list_2 ??
Hope any one can help.