Created
January 11, 2017 23:16
-
-
Save levidurfee/7efbc1e71eeba66f43f21854e217a803 to your computer and use it in GitHub Desktop.
Inheritance in PHP
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 Boy extends Person { | |
public function washHands() { | |
echo "I don't wash my hands..."; | |
} | |
} |
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 | |
interface PersonInterface { | |
public function eat($food); | |
} | |
interface BathroomInterface { | |
public function poop(); | |
public function pee(); | |
public function washHands(); | |
} | |
class Person implements PersonInterface, BathroomInterface { | |
public $name; | |
public $age; | |
public function __construct($name, $age) | |
{ | |
$this->name = $name; | |
$this->age = $age; | |
} | |
public function eat($food) { | |
echo $this->name . ' is eating ' . $food; | |
} | |
public function poop() { | |
echo "I feel better."; | |
} | |
public function pee() { | |
echo "Glad I didn't pee my pants"; | |
} | |
public function washHands() { | |
echo "Yes, I wash my hands."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment