Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/classes/
ovn_cls1.php
ovn_cls2.php
ovn_cls3.php
ovn_cls4.php
ovn_cls5.php
ovn_cls6.php
ovn_cls7.php
ovn_cls5.php
85 lines UTF-8 Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
class Ball
{
// Properties
private $color;
private $radius;
// Methods
public function __construct($color, $radius)
{
$this->color = $color;
$this->radius = $radius;
}
public function get_ball_color()
{
return $this->color;
}
public function get_ball_radius()
{
return $this->radius;
}
public function get_ball()
{
return $this;
}
}
class BallMaterial extends Ball
{
// Properties
private $ball_material;
public function __construct($color, $radius, $ball_material)
{
parent::__construct($color, $radius);
$this->ball_material = $ball_material;
}
public function get_ball_material()
{
return [$this->ball_material];
}
public function get_ball()
{
return $this;
}
}
class BallWeight extends BallMaterial
{
// Properties
private $ball_weight;
public function __construct($color, $radius, $ball_material, $ball_weight)
{
parent::__construct($color, $radius, $ball_material);
$this->ball_weight = $ball_weight;
}
public function get_ball_weight()
{
return [$this->ball_weight];
}
public function get_ball()
{
return $this;
}
}
$ball1 = new BallWeight("red", "12", "stål", "2000");
$ball2 = new BallWeight("blue", "12", "gummi", "100");
$ball3 = new BallWeight("red", "12", "tyg", "10");
$balls = [$ball1->get_ball(), $ball2->get_ball(), $ball3->get_ball()];
// $balls = [[$ball1->get_ball_color(), $ball1->get_ball_radius(), $ball1->get_ball_material(), $ball1->get_ball_weight()], [$ball2->get_ball_color(), $ball2->get_ball_radius(), $ball2->get_ball_material(), $ball2->get_ball_weight()], [$ball3->get_ball_color(), $ball3->get_ball_radius(), $ball3->get_ball_material(), $ball3->get_ball_weight()]];
print_r($balls);