Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple traits extended example
<?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
You can’t perform that action at this time.