Skip to content

Instantly share code, notes, and snippets.

@kuzuha
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuzuha/10949354 to your computer and use it in GitHub Desktop.
Save kuzuha/10949354 to your computer and use it in GitHub Desktop.
<?php
trait AbstractSpeak
{
abstract protected function speak($string);
}
trait PrintSpeak
{
protected function speak($string)
{
print "$string\n";
}
}
trait Hello
{
use AbstractSpeak;
public function sayHello()
{
$this->speak("hello");
}
}
trait Hey
{
use AbstractSpeak;
public function sayHey()
{
$this->speak("hey");
}
}
class Hoge
{
use Hello;
use Hey;
use PrintSpeak;
}
$hoge = new Hoge();
$hoge->sayHello();
$hoge->sayHey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment