Last active
December 21, 2015 07:28
-
-
Save zackexplosion/6271205 to your computer and use it in GitHub Desktop.
an oop example
This file contains 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 Dog{ | |
//宣告『狗吠』方法 | |
function bark(){ | |
//讓『狗』叫 | |
echo '幹!'; // http://www.youtube.com/watch?v=NhqOcOetx2w | |
} | |
} | |
//宣告『人』物件 | |
class People{ | |
//宣告『人』要說的話 | |
$speech; | |
//建立『人』這個物件的時候設定要說的話 | |
function __constructor($speech){ | |
$this->speech = $speech; | |
} | |
//說話的方法 | |
function speak(){ | |
echo $this->speech; | |
} | |
} | |
$speech = '都囉都囉都都囉都囉都都囉都囉'; | |
//建立『人』物件 | |
$p = new People($speech); | |
//建立『狗』物件 | |
$d = new Dog(); | |
//讓『人』說話 | |
$p->speak(); | |
//如果『人』說的話等於我們設定好的台詞 | |
if($p->speech == $speech){ | |
//就讓『狗』吠 | |
$d->bark(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment