Skip to content

Commit ea5d772

Browse files
committed
Buat: pengenalan __construct fungsi
1 parent e951dd3 commit ea5d772

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

4-pengenalan-konstruk.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
class ContohClass {
4+
public $data1;
5+
public $data2;
6+
public function __construct($__data1, $__data2)
7+
{
8+
$this->data1 = $__data1;
9+
$this->data2 = $__data2;
10+
$this->tampilkanDataLewat__construct();
11+
}
12+
13+
protected function tampilkanDataLewat__construct() {
14+
echo 'Fungsi yang di panggil pada saat Objek dibuat: '.$this->data1.' '.$this->data2."\n";
15+
}
16+
17+
public function tampilkanData() {
18+
echo $this->data1.' '.$this->data2."\n";
19+
}
20+
}
21+
22+
$CONTOHCLASS = new ContohClass('satu', 2);
23+
echo "+++++++++++++++++++++++++++++++++++++\n";
24+
sleep(5);
25+
for ($i=0; $i < 5; $i++) {
26+
$CONTOHCLASS->tampilkanData();
27+
}

0 commit comments

Comments
 (0)