Skip to content

Instantly share code, notes, and snippets.

@levidurfee
Created January 11, 2017 23:16
Show Gist options
  • Save levidurfee/7efbc1e71eeba66f43f21854e217a803 to your computer and use it in GitHub Desktop.
Save levidurfee/7efbc1e71eeba66f43f21854e217a803 to your computer and use it in GitHub Desktop.
Inheritance in PHP
<?php
class Boy extends Person {
public function washHands() {
echo "I don't wash my hands...";
}
}
<?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