Last active
August 29, 2015 13:57
-
-
Save amacgregor/9573439 to your computer and use it in GitHub Desktop.
Multiple traits extended 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 Animal { | |
public function roar() { | |
echo "Makes animal sounds"; | |
} | |
} | |
trait Feline { | |
public function roar() { | |
echo "Meowww"; | |
} | |
} | |
trait BigCat { | |
public function kill() { | |
echo "Kill an animal"; | |
} | |
} | |
class Tiger extends Animal { | |
use Feline; | |
use BigCat; | |
} | |
class Cat extends Animal { | |
use Feline; | |
} | |
// Cat class example | |
$cat = new Cat; | |
$cat->roar(); | |
// Tiger class example | |
$tiger = new Tiger; | |
$tiger->roar(); | |
$tiger->kill(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment