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_2.php
48 lines UTF-8 Windows (CRLF)
<?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 2</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Arial;
}
</style>
</head>
<body>
<h2>Olika bollar med egenskaper</h2>
<?php
class Ball {
public $color;
public $radius;
public function __construct($color, $radius) {
$this->color = $color;
$this->radius = $radius;
}
public function printStuffs() {
echo "Färg: $this->color<br>Radie: $this->radius cm";
}
}
$balls = [];
$balls[] = new Ball("grön", 4);
$balls[] = new Ball("röd", 10);
$balls[] = new Ball("ljusblå", 7);
foreach ($balls as $ball) {
echo "<h3>Boll</h3>";
$ball->printStuffs();
}
?>
</body>
</html>