Blog | Beli Rumah | Belajar HTML dan PHP | Kontak | Gmail | Uang Adsense
Audit Sistem Informasi
Sistem Informasi (S1)
Manajemen Informatika
Komputer dan Pendidikan
Pengobatan Ruqyah
Daftar Isi | Skripsi SI | B. Arab | Sertifikat Komputer Internasional | PrivacyPolicy | Inggris Arab

Friday, August 28, 2020

PBO 2

Masuk cpanel Lab Katabah

Buka folder masing-masing

Buatlah subfolder: dua


Buatlah file 1kelas.php

Ketik script ini:

<?php 

class person {

 

}

?>


=====

Buat lagi file baru: 2properti.php

Ketik script ini:

<?php 

class person {

var $name;

}

?>


===

Buat lagi file baru: 3metod.php

Ketik script ini:

<?php 

class person {

var $name; 

function set_name($new_name) { 

$this->name = $new_name;  

  }

 

    function get_name() {

return $this->name;

}

?>


====

Buat lagi file baru: 4instance.php

Ketik script ini:

<?php  

include("3metod.php");

?>

<?php 

$prabu = new person();

$kian = new person;


$prabu->set_name("Prabu Siliwangi");

$kian->set_name("Kian Santang");

 

echo "Prabu's full name: " . $prabu->get_name();

echo "<br>";

echo "Kian's full name: " . $kian->get_name(); 

?>


===

Buat lagi file baru: 5publik.php

Ketik script ini:

<?php 

class person {

public $name; 

function set_name($new_name) { 

$this->name = $new_name;  

  }

 

    function get_name() {

return $this->name;

}

?>


<?php

$person1 = new Person();

// properti bisa di akses secara langsung

echo "Hai ".$person1->name='Prabu Siliwangi';

echo "<hr>";

// method bisa di akses secara langsung

echo $person1->get_name();

?>


===

Buat lagi file baru: 6private.php

Ketik script ini:

<?php 

class person {

private $name; 

function set_name($new_name) { 

$this->name = $new_name;  

  }

 

    function get_name() {

return $this->name;

}

?>


<?php

$person1 = new Person();

// properti bisa di akses secara langsung

echo "Hai ".$person1->name='Prabu Siliwangi';

echo "<hr>";

// methob tidak bisa di akses secara langsung

echo $person1->get_name();

?>


==

Buat lagi file baru: 7protek.php

Ketik script ini:

<?php 

class person {

protected $name; 

function set_name($new_name) { 

$this->name = $new_name;  

  }

 

    function get_name() {

return $this->name;

}

?>


<?php

$person1 = new Person();

// set value dari properti name

$person1->set_name('Kian Santang Algaruti');

// akses value dari properti name

echo $person1->get_name();

// properti tidak bisa di akses secara langsung, kana muncul error

echo "Hai ".$person1->name='Prabu Siliwangi';

echo "<hr>";

?>



Sumber:

belajarphp.net/belajar-konsep-oop-php

"Investasi Emas dan Reksadana, Untung Mana?."
Youtube: Katabah Com: Menuju 1 jt Konten :)

No comments:

Post a Comment