Skip to content

Instantly share code, notes, and snippets.

@LeviSchuck
Created March 20, 2011 18:35
Show Gist options
  • Save LeviSchuck/878537 to your computer and use it in GitHub Desktop.
Save LeviSchuck/878537 to your computer and use it in GitHub Desktop.
PHP OOP Tutorial 3: Implementing interfaces, utilizing structure
<?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