Skip to content

Instantly share code, notes, and snippets.

@ombak
Last active May 29, 2020 10:23
Show Gist options
  • Select an option

  • Save ombak/35084740c7ede02472f1caacfe78f6a2 to your computer and use it in GitHub Desktop.

Select an option

Save ombak/35084740c7ede02472f1caacfe78f6a2 to your computer and use it in GitHub Desktop.
<?php
/* class pertama
*/
class ClassSaya {
public $prop1 = 'Saya properti pertama!';
/* method __construct
*/
public function __construct() {
echo 'Ini adalah method __construct dari class "' . __CLASS__ . '"-';
}
/* magic method
*/
public function __toString() {
echo 'Ini adalah method toString';
return $this->getProperty();
}
/* method __destruct
*/
public function __destruct() {
echo 'Ini adalah method __destruct dari class "' . __CLASS__ . '"-';
}
/* method memberi nilai baru pada properties
*/
public function setProperty ($newval) {
$this->prop1 = $newval;
}
/* method mendapatkan nilai dari method set
*/
public function getProperty() {
return $this->prop1 . "-";
}
}
/* class kedua yang merupakan inheritance dari classSaya
*/
class ClassLain extends ClassSaya {
public function newMethod() {
echo 'Ini adalah method __destruct dari class "' . __CLASS__ . '"-';
}
}
$objectLain = new ClassLain();
echo $objectLain->newMethod();
echo $objectLain->getProperty();
echo 'penutup';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment