Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/exercises/classes/
5 filer
classes_4.php
87 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Klasser 4</title> <!-- uppgift 5 & 6 blev "automatiskt" gjorda när jag gjorde denna! -->
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Arial;
}
</style>
</head>
<body>
<h2>Olika bollar med egenskaper</h2>
<br>
<?php
class Ball {
private $color;
private $radius;
public function __construct($color, $radius) {
$this->color = $color;
$this->radius = $radius;
}
public function printStuffs() {
echo "<strong>Färg:</strong> $this->color<br><strong>Radie:</strong> $this->radius cm";
}
}
class MagicBall extends Ball {
private $ability;
public function __construct($color, $radius, $ability) {
parent::__construct($color, $radius);
$this->ability = $ability;
}
public function printStuffs() {
parent::printStuffs();
echo "<br><strong>Specialsak:</strong> $this->ability";
}
}
class LinguisticBall extends Ball {
private $language;
public function __construct($color, $radius, $language) {
parent::__construct($color, $radius);
$this->language = $language;
}
public function printStuffs() {
parent::printStuffs();
echo "<br><strong>Språk</strong>: $this->language";
}
}
$balls = [];
$balls[] = new Ball("grön", 4);
$balls[] = new MagicBall("svart", 19, "har ögon men är färgblind, och kan prata med djur");
$balls[] = new Ball("röd", 10);
$balls[] = new Ball("ljusblå", 7);
$balls[] = new MagicBall("orange", 3, "kan programmera i JavaScript");
$balls[] = new LinguisticBall("gul", 13, "kan mongoliska flytande");
$balls[] = new LinguisticBall("brun", 28, "kan katalanska, nauhatl och lär sig just nu maori");
foreach ($balls as $ball) {
echo "<h3>Boll</h3>";
$ball->printStuffs();
echo "<br><br>";
}
?>
<br>
<br>
<br>
</body>
</html>