AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

[PHP] Objektliste

Ein Thema von Luckie · begonnen am 3. Feb 2012 · letzter Beitrag vom 3. Feb 2012
 
Benutzerbild von Luckie
Luckie

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

AW: [PHP] Objektliste

  Alt 3. Feb 2012, 19:23
Äh, ja. Verursacht Blitzdingsen eigentlich Krebs? *blitz*

Aber irgendwas verstehe ich bei den Array Funktionen noch nicht so richtig. Ich dachte mit array_push wird ein neues Element an das Array angehangen. Allerdings, wenn ich mir die Liste ausgeben lasse, beinhalten alle Elemente nur das zu letzt hinzugefügte Objekt.

Aktueller Code:
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 $this->Vorname;
      }
   }
?>

<?php
   class ContactList {
      
      private $Contact;
      private $List = array();
      
      public function SetContact($Contact) {
         $this->Contact = $Contact;
      }
      
      public function Add($Contact) {
         array_push($this->List, $Contact);
         echo $Contact->GetName()."<br>";
      }
      
      public function Contacts() {
         return $this->List;         
      }
   }
?>


<?php
   include("Contact.php");
   include("ContactList.php");

    $Contact = new Contact();
    $ContactList = new ContactList();
    
    $Contact->SetName("Puff");
    $Contact->SetVorname("Michael");
    $ContactList->Add($Contact);
    $Contact->SetName("Müller");
    $Contact->SetVorname("Karl");
    $ContactList->Add($Contact);
    $Contact->SetName("Schmidt");
    $Contact->SetVorname("Hans");
    $ContactList->Add($Contact);
    
    echo "<pre>", print_r($ContactList), "</pre>";
    
    foreach($ContactList->Contacts() as $Value) {
       echo $Value->GetName().", ".$Value->GetVorname()."<br>";
       //print_r($Value);
    }
?>
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:18 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz