note 127064 added to ref.classobj

From: Date: Sun, 15 May 2022 15:40:24 +0000
Subject: note 127064 added to ref.classobj
Groups: php.notes 
Request: Send a blank email to php-notes+get-218394@lists.php.net to get a copy of this message
<?php //Teil1 //artikel.class.php class Artikel { //Attribute protected $artikelNr; protected $bezeichnung; protected $bestand; //Konstruktor public function __construct($nr, $bez, $best) { $this->artikelNr = $nr; $this->bezeichnung = $bez; $this->bestand = $best; } //Funktionen public function ausbuchen($menge) { if($menge <= $this->bestand) { $this->bestand = $this->bestand - $menge; return "<p>Bestand neu: $this->bestand</p>"; } else { return "<p>Buchung nicht möglich</p>"; } } } // Teil 2 <?php //sensoren.class.php class Sensoren extends Artikel { //Attribute // geerbt von der Klasse Artikel: //protected $artikelNr; //protected $bezeichnung; //protected $bestand; // hinzu kommt: private $ausgangssignal; /* elektrisch: analog oder digital */ private $eingangssignal; /* thermisch, chemisch, mechanisch, magnetisch */ //Konstruktor public function __construct($nr, $bez, $best, $as, $es) { //Konstruktoren werden nicht vererbt, es muss bei //parametrisierten Konstruktoren zuerst der Eltern //Konstruktor bedient werden parent::__construct($nr, $bez, $best); $this->ausgangssignal = $as; switch ($es) { case 1: $this->eingangssignal = "thermisch"; break; case 2: $this->eingangssignal = "chemisch"; break; case 3: $this->eingangssignal = "mechanisch"; break; case 4: $this->eingangssignal = "magnetisch"; break; default: $this->eingangssignal = "thermisch"; } /* ODER: if($es == 1) { $this->eingangssignal = "thermisch"; } else if($es == 2) { $this->eingangssignal = "chemisch"; } else if($es == 3) { $this->eingangssignal = "mechanisch"; } else if($es == 4) { $this->eingangssignal = "magnetisch"; } else { $this->eingangssignal = "thermisch"; } */ } public function getAusgangssignal() { return $this->ausgangssignal; } public function getEingangssignal() { return $this->eingangssignal; } public function getDaten() { return "<p>ArtikelNr: $this->artikelNr<br> Bezeichnung: $this->bezeichnung<br> Bestand: $this->bestand<br> Eingangssignal: $this->eingangssignal<br> Ausgangssignal: $this->ausgangssignal</p>"; } } // Aufruf <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php require_once "artikel.class.php"; require_once "sensoren.class.php"; $s = new Sensoren(12345, "PT100", 50, "digital", 1); echo $s->getDaten(); echo $s->ausbuchen(20); echo $s->ausbuchen(50); ?> </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/127064 Del: integrated -- https://main.php.net/note/delete/127064/integrated Del: useless -- https://main.php.net/note/delete/127064/useless Del: bad code -- https://main.php.net/note/delete/127064/bad+code Del: spam -- https://main.php.net/note/delete/127064/spam Del: non-english -- https://main.php.net/note/delete/127064/non-english Del: in docs -- https://main.php.net/note/delete/127064/in+docs Del: other reasons-- https://main.php.net/note/delete/127064 Reject -- https://main.php.net/note/reject/127064 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218394) next »