-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructor.php
43 lines (35 loc) · 1.05 KB
/
constructor.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
<?php
#4 Constructor
// Sebuah method yang khusus yang ada di dalam sebuah kelas
// method yang dijalankan ketika sebuah kelas di instansiasi / dibuat object
// jualan produk
// Komik
// Game
class Produk {
public $judul,
$creator,
$penerbit,
$harga;
public function __construct($judul = "judul",
$creator = "creator", $penerbit = "penerbit", $harga = 0)
{
$this->judul = $judul;
$this->creator = $creator;
$this->penerbit = $penerbit;
$this->harga = $harga;
}
public function sayHello(){
return "Hello World!";
}
public function getLabel(){
return "$this->creator, $this->penerbit";
}
}
$produk1 = new Produk("Naruto", "Masashi Kishimoto", "Shounen Jump", 30000);
$produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer Entertainment", 250000);
$produk3 = new Produk("Dragon Ball");
echo "Komik : " . $produk1->getLabel();
echo "<br>";
echo "Game : " . $produk2->getLabel();
echo "<br>";
var_dump($produk3);