-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuzdevums.php
More file actions
71 lines (60 loc) · 1.48 KB
/
uzdevums.php
File metadata and controls
71 lines (60 loc) · 1.48 KB
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
<?php declare(strict_types=1);
class Car {
protected int $volume;
protected string $name;
public function __construct(string $name, int $volume){
$this->name = $name;
$this->volume = $volume;
}
/**
* @return int
*/
public function getVolume(): int {
return $this->volume;
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
}
class BMW extends Car {
public function canChangeTires():string {
return 'true';
}
}
class Wolksvagen extends Car {
public function hasComfySeats():string {
return 'false';
}
}
class Golf extends Car {
protected ?string $model;
public function __construct(string $name, int $volume,string $model=null) {
$this->name = $name;
$this->volume = $volume;
$this->model = $model;
}
public function model():string {
return $this->model;
}
}
$cars = [
new BMW("Jane's car", 200),
new Wolksvagen("John's car", 100),
new Golf("Frank's car", 300, 'A7')
];
foreach ($cars as $car) {
echo $car->getName() . PHP_EOL;
echo $car->getVolume() . 'l' . PHP_EOL;
if($car instanceof Golf){
echo 'Model: ' . $car->model();
}
elseif($car instanceof BMW){
echo 'Can change tires? ' . $car->canChangeTires();
}elseif($car instanceof Wolksvagen){
echo 'Has comfortable seats? ' . $car->hasComfySeats();
}
echo PHP_EOL . PHP_EOL;
}