Skip to content

Instantly share code, notes, and snippets.

@bigkiandi
Created June 18, 2017 22:44

Revisions

  1. bigkiandi created this gist Jun 18, 2017.
    19 changes: 19 additions & 0 deletions enkapsulasi.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?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();
    ?>
    19 changes: 19 additions & 0 deletions oop.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?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();