Einzelnen Beitrag anzeigen
  #15  
Alt 10.08.2009, 13:45:17
DokuLeseHemmung DokuLeseHemmung ist offline
SELFPHP Experte
 
Registriert seit: Jun 2008
Alter: 15
Beiträge: 2.269
AW: [PHP5 /OOP] Auf Eigenschaften der Vaterklasse zugreifen?

PHP-Code:
<?php
error_reporting
(-1);
ini_set('display_errors'TRUE);



Class 
ListItem
{

  protected 
$Value null// property
  
protected $Container  null// property
  
  
public function __construct($value)
  {
    
$this->setValue($value);
  }

  public function 
setContainer(ListBox $value)
  {
    
$this->Container $value;
  }

  public function 
getContainer()
  {
    return 
$this->Container;
  }

  public function 
setValue($value)
  {
    
$this->Value $value;
  }

  public function 
getValue()
  {
    return 
$this->Value;
  }
  
  public function 
test()
  {
    echo 
$this->Value.'<br>';
    echo 
"ich stecke im Container ".get_class($this->Container). '<br>';
    echo 
"der Container heißt: ".$this->Container->getname(). '<hr>';
  }

  
}


class 
ListBox
{
  protected 
$elemente = array();

  protected 
$name // property

  
public function __construct($name)
  {
    
$this->setname($name);
  }
  

  public function 
setname($value)
  {
    
$this->name $value;
  }

  public function 
getname()
  {
    return 
$this->name;
  }
  public function 
add(ListItem $item)
  {
    
$item->setContainer($this);
    
$this->elemente[] = $item;
  }
  
  public function 
tuwas()
  {
    foreach(
$this->elemente as $element)
      
$element->test();
  }
}

$lb = new ListBox('Das tolle Ding');
$lb->add(new ListItem('rot'));
$lb->add(new ListItem('blau'));
$lb->tuwas();
Mit Zitat antworten