-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class5.php
180 lines (152 loc) · 4.39 KB
/
Class5.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<title>Class/Week 5</title>
</head>
<body>
<h3> Week 5 Objects </h3>
<?php
class KeepingItSimple {
}
$first= new KeepingItSimple();
print_r($first);
echo "</br>";
echo gettype($first);
?>
<?php
class People {
public $name = "noname";
}
$firstPerson = new People();
$secondPerson = new People();
$thirdPerson = new People();
$firstPerson->name;
$secondPerson->name="tim";
$thirdPerson->name="Jessica";
echo $firstPerson->name;
echo "</br>";
echo $secondPerson->name;
echo "</br>";
echo $thirdPerson->name;
?>
<?php
class SystemInfo {
private function get_date() {
return date ("y/m/d");
}
private function getVersionOfPhp() {
return phpversion();
//return php_ini_loaded_file();
}
public function getInformation() {
$date = $this->get_date();
$version = $this->getVersionOfPhp();
echo "Todays date is: ".$date."</br>";
echo "We are using the version ".$version."</br>";
}
}
$mySystem = new SystemInfo();
$myNewSystem = new SystemInfo();
$mySystem->getInformation();
//$myNewSystem->getInformation();
?>
<?php
class myClass {
function first() {
return true;
}
function second() {
return true;
}
}
$classObject = get_class_methods('myClass');
$classObject1 = get_class_methods(new myClass());
foreach($classObject as $x) {
echo $x. "</br";
}
echo "</br>"."</br>";
foreach($classObject1 as $y) {
echo $y."</br>";
}
?>
<hr>
<?php
class Sound {
function _construct() {
echo "Some sound object is created"."</br>";
}
function differentSound($bark) {
echo "Some sound object is created $bark "."</br>";
}
}
//$newSound = new Sound();
$bark = new Sound;
$bark->differentSound("Woof Woof");
echo "test";
//echo $bark;
//echo $newSoundBark;
?>
<hr>
<?php
class Math {
function addition (...$value) {
$sum = 0;
foreach($value as $num){
$sum+=$num;
}
return $sum;
}
}
$first = new Math();
$first->addition();
echo "<br>";
echo $first->addition(1,2,3);
echo "</br>";
echo $first->addition(55,42);
echo "<br>";
?>
<hr>
<?php
class Math1 {
function addition() {
$sum = 0;
$args = func_get_args();
if (empty($args)){
return 0;
}
foreach($args as $num){
$sum+=$num;
}
return $sum;
}
}
$second = new Math1();
$second->addition();
echo "<br>";
echo $second->addition(1,2,3);
echo "</br>";
echo $second->addition(55,42);
echo "<br>";
echo $second->addition(994,27,35,5,88);
echo "<br>";
?>
<hr>
<?php
class Student {
public $name;
public $status;
function __construct($name, $status) {
$this->name = $name;
$this->status = $status;
}
function __toString(){
return "Student: $this->name, Status: $this->status"."</br>";
}
}
$student1 = new Student("Jessica", "Junior");
$student2 = new Student("Troy", "Senior");
echo $student1;
echo $student2;
?>
</body>
</html>