-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.php
More file actions
74 lines (57 loc) · 1.33 KB
/
oop.php
File metadata and controls
74 lines (57 loc) · 1.33 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
72
73
74
<?php
class Fruit {
// Properties
public $name;
public $color;
// Methods
// set_name, get_name, new, $this-> are key words
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
function set_color($color) {
$this->color = $color;
}
function get_color() {
return $this->color;
}
}
$apple = new Fruit();
$apple->set_name('Apple');
$apple->set_color('red');
$banana = new Fruit();
$banana->set_name('Banana');
$banana->set_color('yellow');
echo "Name: " . $apple->get_name();
echo '<br>';
echo "Color: " . $apple->get_color();
echo '<br>';
echo "Name: " . $banana->get_name();
echo '<br>';
echo "Color: " . $banana->get_color();
echo '<br>';echo '<br>';echo '<br>';
Class Meyve {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function get_name() {
return $this->name;
}
function get_color() {
return $this->color;
}
}
$apple1 = new Meyve("Apple", "red");
echo "Name: " . $apple1->get_name();
echo '<br>';
echo "Color: " . $apple1->get_color();
echo '<br>';
$banana1 = new Meyve("Banana", "yellow");
echo "Name: " . $banana1->get_name();
echo '<br>';
echo "Color: " . $banana1->get_color();