note 127065 added to ref.classobj
| From: | ott at web dot de | Date: | Sun, 15 May 2022 15:48:17 +0000 |
| Subject: | note 127065 added to ref.classobj | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218395@lists.php.net to get a copy of this message | ||
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>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 2a02:8071:885:8701:3d7d:4ba2:1534:419a)
----
Manual Page -- https://php.net/manual/en/ref.classobj.php
Edit -- https://main.php.net/note/edit/127065
Del: integrated -- https://main.php.net/note/delete/127065/integrated
Del: useless -- https://main.php.net/note/delete/127065/useless
Del: bad code -- https://main.php.net/note/delete/127065/bad+code
Del: spam -- https://main.php.net/note/delete/127065/spam
Del: non-english -- https://main.php.net/note/delete/127065/non-english
Del: in docs -- https://main.php.net/note/delete/127065/in+docs
Del: other reasons-- https://main.php.net/note/delete/127065
Reject -- https://main.php.net/note/reject/127065
Search -- https://main.php.net/manage/user-notes.php