Show sourcecode
The following files exists in this folder. Click to view.
ovn_kls1.php
ovn_kls2.php
ovn_kls3.php
ovn_kls4.php
ovn_kls5.php
ovn_kls6.php
ovn_kls7.php
ovn_kls4.php
72 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
<?php
// Title: Klasser 4
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>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Klasser 4</title>
</head>
<body>
<?php
class Ball {
private $color;
private $radius;
public function __construct($color, $radius) {
$this->color = $color;
$this->radius = $radius;
}
public function getColor() {
return $this->color;
}
public function getRadius() {
return $this->radius;
}
}
class BasketBall extends Ball {
private $type;
public function __construct($color, $radius) {
parent::__construct($color, $radius);
$this->type = "Basketboll";
}
public function getType() {
return $this->type;
}
}
class Football extends Ball {
private $type;
public function __construct($color, $radius) {
parent::__construct($color, $radius);
$this->type = "Fotboll";
}
public function getType() {
return $this->type;
}
}
$items = [];
array_push($items, new BasketBall("Röd", 10));
array_push($items, new Football("Gul", 20));
for ($i = 0; $i < count($items); $i++) {
$item = $items[$i];
echo $item->getType() . "<br>";
echo "Färg: " . $item->getColor() . "<br>";
echo "Radius: " . $item->getRadius() . "<br><hr>";
}
?>
</body>
</html>