note 127065 deleted from ref.classobj by girgias

From: Date: Sun, 15 May 2022 16:11:12 +0000
Subject: note 127065 deleted from ref.classobj by girgias
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218406@lists.php.net to get a copy of this message
Note Submitter: ott at web dot de ---- abstract class Teilnehmer { //Attribute protected $name; protected $vorname; protected $code; //Konstruktor public function __construct($n, $vn, $c) { $this->name = $n; $this->vorname = $vn; if($c[0]=="#") { $this->code = $c; } else { $this->code = "Fehler"; } } } /tbintern.class.php // Teil 2 class TNIntern extends Teilnehmer { //Attribute private $abteilung; //Klassenattribut private static $anzahl = 0; //Konstruktor public function __construct($n, $vn, $c, $abt) { parent::__construct($n, $vn, $c); $this->abteilung = $abt; self::$anzahl++; //Zugriff auf statisches Attribut mit self:: } //Getter public function getDaten() { return "<p>Name: $this->name <br> Vorname: $this->vorname <br> Code: $this->code <br> Abteilung: $this->abteilung </p>"; } public static function getAnzahl() { return self::$anzahl; } } // Aufruf <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <?php require_once "teilnehmer.class.php"; require_once "tnintern.class.php"; //noch kein Teilnehmer instanziiert: echo "<p>Teilnehmer: ".TNIntern::getAnzahl()."<br>"; //einen Teilnehmer instanziieren: $t1 = new TNIntern("Mustermann", "Max", "#TE#239#43", "Technik"); echo $t1->getDaten(); echo "-----------------------<br>"; echo "<p>Teilnehmer: ".TNIntern::getAnzahl()."<br>"; echo "-----------------------<br>"; //einen weiteren Teilnehmer instanziieren: $t2= new TNIntern("Fröhlich","Florentine", "_EW#511#50", "Entwicklung"); echo $t2->getDaten(); echo "-----------------------<br>"; echo "<p>Teilnehmer: ".TNIntern::getAnzahl() ."<br>"; echo "-----------------------<br>"; //noch einen weiteren Teilnehmer instanziieren: $t3 = new TNIntern("S","Mi", "#BB#511#50", "Design"); echo $t3->getDaten(); echo "-----------------------<br>"; echo "<p>Teilnehmer: ".TNIntern::getAnzahl() ."<br>"; echo "-----------------------<br>"; ?> </body> </html>

« previous php.notes (#218406) next »