Last active
May 29, 2020 10:42
-
-
Save ombak/c8996181e57abcdcca8ec0b9c110d535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* class pertama | |
| */ | |
| class ClassSaya { | |
| public $prop1 = 'Saya properti pertama!'; | |
| /* method __construct | |
| */ | |
| public function __construct() { | |
| echo 'Ini adalah method __construct dari class "' . __CLASS__ . '"-'; | |
| } | |
| /* 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 | |
| */ | |
| protected function getProperty() { | |
| return $this->prop1 . "-"; | |
| } | |
| } | |
| /* class kedua yang merupakan inheritance dari classSaya | |
| */ | |
| class ClassLain extends ClassSaya { | |
| /* method yang memanggil method protected | |
| */ | |
| public function callProtected() { | |
| return $this->getProperty(); | |
| } | |
| } | |
| $objectLain = new ClassLain; | |
| echo $objectLain->callProtected(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment