-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
75 lines (56 loc) · 1.56 KB
/
index.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
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
<?php
class Human {
public $hair = "black";
//Called only when the this class is used to create a new object
public function __construct()
{
echo 'The class "', __CLASS__, '" was initiated!<br />';
}
public function __destruct()
{
echo 'The class "', __CLASS__, '" was destroyed.<br />';
}
public function setHairColor($newval)
{
$this->hair = $newval;
}
public function getHairColor()
{
return $this->hair . "<br />";
}
}
class Male extends Human
{
public $sex = "M";
//Called when getting destroyed...
public function __destruct()
{
parent::__destruct(); //Call the parent class's destruct 1st
echo 'The class "', __CLASS__, '" was destroyed.<br />';
}
}
class Female extends Human
{
public $sex = "F";
//Called when getting destroyed...
public function __destruct()
{
parent::__destruct(); //Call the parent class's destruct 1st
echo 'The class "', __CLASS__, '" was destroyed.<br />';
}
}
$boy = new Male;
$girl = new Female;
?><!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<?php
$boy->setHairColor("green");
echo $boy->getHairColor();
echo $girl->sex . "<br/>";
?>
</body>
</html>