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_kls2.php
47 lines UTF-8 Windows (CRLF)
<?php
// Title: Klasser 2
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 2</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;
}
}
$ball_1 = new Ball("Röd", 10);
$ball_2 = new Ball("Gul", 20);
$ball_3 = new Ball("Blå", 30);
echo "Färg: " . $ball_1->getColor() . "<br>";
echo "Radius: " . $ball_1->getRadius() . "<br><hr>";
echo "Färg: " . $ball_2->getColor() . "<br>";
echo "Radius: " . $ball_2->getRadius() . "<br><hr>";
echo "Färg: " . $ball_3->getColor() . "<br>";
echo "Radius: " . $ball_3->getRadius() . "<br>";
?>
</body>
</html>