-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_functions.php
executable file
·39 lines (30 loc) · 1.05 KB
/
abstract_functions.php
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
#!/usr/bin/php8.1
<?php
abstract class Value { // Must be abstract class to have abstract method.
public float $value = 0;
public string $label;
public function __construct(float $value, string $label = "") {
$this->value = $value;
$this->label = $label;
}
public abstract function show() : void;
}
class Datum extends Value {
public string $description;
public function __construct(float $value, string $label, string $description = "") {
$this->value = $value;
$this->label = $label;
$this->description = $description;
}
public function show() : void {
print("Value: " . $this->value
. "\nLabel: " . $this->label
. "\nDescription: " . $this->description . "\n"
);
}
}
class Content extends Datum {
}
// $temperature = new Value(24, "Health for humans temperature in degree Celsius"); // One cannot instantiate.
$page = new Content(666, "Page of Harry Potter book", "The satanistic ritual hidden in the book for kids. Oh noes!");
$page->show();