Skip to content

Instantly share code, notes, and snippets.

@Aziz-Rahman
Last active August 29, 2015 14:16
Show Gist options
  • Save Aziz-Rahman/53ab8066826a8c9faeab to your computer and use it in GitHub Desktop.
Save Aziz-Rahman/53ab8066826a8c9faeab to your computer and use it in GitHub Desktop.
Construtor & Destructor ( OOP PHP )
<?php
class motor{
private $model = "bebek";
private $warna = "hitam";
public function __construct(){
echo "method konstruktor di jalankan"."<br/>";
}
public function __destruct(){
echo "method destruktor di jalankan"."<br/>";
}
public function tampilkanmotor(){
echo "Motor ini bermodel ".$this->model." dan berwarna ".$this->warna ."<br/>";
}
}
// Menjalankan perintah
$motorgue = new motor;
$motorgue->tampilkanmotor();
// ========== Hasil ( Output ) =========
// method konstruktor di jalankan
// Motor ini bermodel bebek dan berwarna hitam
// method destruktor di jalankan
// ========== *Note =========
// Construtor adalah sebuah method yang di eksekusi atau di jalankan secara otomatis ketika sebuah objek telah di instansiasi/telah di buat.
// Destructor adalah sebuah method yang di jalankan secara otomatis ketika sebuah objek tidak lagi memiliki fungsi atau saat sebuah objek telah selesai di gunakan .
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment