<?php
// persoon.php
// persoon klasse (abstracte klasse, basis klasse)
class persoon {
// eigenschappen (voor een basisklasse scope = protected)
protected $naam;
protected $voornaam;
protected $geslacht;
protected $telefoon;
// methodes
public function __construct($nm = "", $vm = "", $gl = "", $tel = "") {
// constructor met standaard lege eigenschappen (= "")
$this->naam = $nm;
$this->voornaam = $vm;
$this->geslacht = $gl;
$this->telefoon = $tel;
}
public function toon_eigenschappen() {
$meld = "Naam: " . $this->naam . "<br>";
$meld .= "Voornaam: " . $this->voornaam . "<br>";
$meld .= "Geslacht: " . $this->geslacht . "<br>";
$meld .= "Telefoon: " . $this->telefoon . "<br>";
echo $meld . "<br>";
}
}
require "persoon.php";
$pers1 = new persoon("Jan","Janssens","M","0123456789");
public function __construct($nm = "", $vm = "", $gl = "", $tel = "") {
// constructor met standaard lege eigenschappen (= "")
$this->naam = $nm;
$this->voornaam = $vm;
$this->geslacht = $gl;
$this->telefoon = $tel;
}
require "leerling.php";
$lln1 = new leerling("Ria","Peeters","V","13246546" ,"5AIT","PeetersR");
echo $lln1->get_gebruikersnaam() ."";
In the 'codesnippets' section of this website you can find other examples of classes such as a database class, a table class, etc...
<?php
class leerling {
...
public function get_gebruikersnaam() {
return $this->gebruikersnaam;
}
...
}
require "persoon.php"; // basisklasse definitie nodig
require "leerling.php";
echo "Een object van de klasse leerling:" . "";
$lln1 = new leerling("Ria","Peeters","V","13246546" ,"5AIT","PeetersR");
$lln1->toon_eigenschappen();
echo $lln1->get_gebruikersnaam() ."";
<?php
// leerling.php
// leerling klasse (erft de eigenschappen van persoon)
class leerling extends persoon {
// eigenschappen (scope = private)
private $klas;
private $gebruikersnaam;
// methodes
public function __construct($nm = "", $vm = "", $gl = "", $tel = "", $kl = "", $geb = "") {
// persoon eigenschappen initialiseren
parent::__construct($nm, $vm, $gl, $tel);
$this->klas = $kl;
$this->gebruikersnaam = $geb;
}
public function toon_eigenschappen() {
$meld = "Naam: " . $this->naam . "<br>";
$meld .= "Voornaam: " . $this->voornaam . "<br>";
$meld .= "Geslacht: " . $this->geslacht . "<br>";
$meld .= "Telefoon: " . $this->telefoon . "<br>";
$meld .= "Klas: " . $this->klas . "<br>";
$meld .= "Gebruikersnaam: " . $this->gebruikersnaam . "<br>";
echo $meld . "<br>";
}
public function get_gebruikersnaam() {
return $this->gebruikersnaam;
}
}