XaraX: OOP - Probleme mit Instanzvariablen

Beitrag lesen

Hallo,

<?php
class A
{
var $id = NULL;

# http://de3.php.net/manual/de/language.oop.php#keyword.class
    # bitte die Anmerkung zu PHP 4.x lesen

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");

# prin_r($a); zum Testen rein

$b = new B($a);

# dann hier mit new B($a->get_id()) arbeiten

$b->show_my_a_id();

$a->set_id("2");

$b->show_my_a_id();
?>

Gruß aus Berlin!
eddi