Created
March 20, 2011 18:35
-
-
Save LeviSchuck/878537 to your computer and use it in GitHub Desktop.
PHP OOP Tutorial 3: Implementing interfaces, utilizing structure
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 | |
//PHP Object Oriented Programming Tutorial 3 | |
interface person { | |
function myName(); | |
function myPosition(); | |
} | |
class employee implements person { | |
public function myName(){ | |
return "Happy ". ucfirst(__CLASS__); | |
} | |
public function myPosition() { | |
return "Lowly Jail cell cleaner"; | |
} | |
} | |
class executive implements person { | |
public function myName(){ | |
return "Happy ". ucfirst(__CLASS__); | |
} | |
public function myPosition() { | |
return "High guy with a desk"; | |
} | |
} | |
class unemployed implements person { | |
public function myName(){ | |
return "Happily ". ucfirst(__CLASS__); | |
} | |
public function myPosition() { | |
return "Currently outside an ally in a box"; | |
} | |
} | |
$array = array(); | |
$exec = new executive(); | |
$unem = new unemployed(); | |
$empl = new employee(); | |
$empl2 = new employee(); | |
//lets put in some people into our array. | |
$array[] = $unem; | |
$array[] = $empl; | |
$array[] = $exec; | |
$array[] = $empl2; | |
$array[] = new DOMDocument(); | |
foreach($array as $person){ | |
if($person instanceof person){ | |
echo $person->myName()." ".$person->myPosition()."\n"; | |
} | |
} | |
echo "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment