Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

[PHP] Objektliste

  Alt 3. Feb 2012, 18:45
Ich überarbeite gerade ein privates Projekt und versuche gerade eine Objektliste zu erstellen.

Klasse Conatct:
Code:
<?php
   class Contact
   {
      private $Name = "";
      private $Vorname = "";
      
      public function SetName($Name) {
         $this->Name = $Name;
      }
      
      public function GetName() {
         return $this->Name;
      }
      
      public function SetVorname($Vorname) {
         $this->Vorname = $Vorname;
      }
      
      public function GetVorname() {
         return $tis->Vorname;
      }
   }
?>
Klasse ContactList:
Code:
<?php
   class ContactList {
      
      private $Contact;
      private $List = array();
      
      public function SetContact($Contact) {
         $this->Contact = $Contact;
      }
      
      public function Add($Contact) {
         array_push($this->List, $Contact);
      }
   }
?>
Und der test:
Code:
<?php
   include("Contact.php");
   include("ContactList.php");

    $Contact = new Contact();
    $ContactList = new ContactList();
    
    $Contact->SetName("Puff");
    $Contact->SetVorname("Michael");
    $ContactList->Add($ContactList);
    $Contact->SetName("Müller");
    $Contact->SetVorname("Karl");
    $ContactList->Add($ContactList);
    $Contact->SetName("Schmidt");
    $Contact->SetVorname("Hans");
    $ContactList->Add($ContactList);
    
    print_r($ContactList);
//    foreach($ContactList as $Contact) {
//       echo $Contact->GetName().", ".$Contact->GetVorname()."<br>";
//    }
?>
print_r gibt mir aus:
Code:
ContactList Object ( [Contact:ContactList:private] =>[List:ContactList:private] => Array ( [0] => ContactList Object *RECURSION* [1] => ContactList Object *RECURSION* [2] => ContactList Object *RECURSION* ) )
Und die auskommentierte Schleife gibt mir gar nichts aus.

Ja, was mache ich da falsch? Ich habe leider keinen Plan.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat