Skip to content

Instantly share code, notes, and snippets.

@bigkiandi
Created June 18, 2017 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigkiandi/ab774ca6ae3019a29eb305749e934e28 to your computer and use it in GitHub Desktop.
Save bigkiandi/ab774ca6ae3019a29eb305749e934e28 to your computer and use it in GitHub Desktop.
<?php
// buat class komputer
class komputer {
// property dengan hak akses protected
protected $jenis_processor = "Intel Core i7-4790 3.6Ghz";
}
// buat class laptop
class laptop extends komputer{
public function tampilkan_processor() {
return $this->jenis_processor;
}
}
// buat objek dari class laptop (instansiasi)
$laptop_baru = new laptop();
// jalankan method
echo $laptop_baru->tampilkan_processor();
?>
<?php
class leptop {
// buat properti untuk class leptop
var $pimilik
// buat method
function idupinLeptop()
{
return "NYALA";
}
}
// buat object dari class leptop
$leptop_andi = new leptop();
// set property
$leptop_andi->pemilik = "ANDI";
// tampilkan property di browser
echo $leptop_andi->pemilik;
echo $leptop_andi->idupinLeptop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment