Skip to content

Instantly share code, notes, and snippets.

@kamekoopa
Created July 12, 2011 09:34
Show Gist options
  • Save kamekoopa/1077683 to your computer and use it in GitHub Desktop.
Save kamekoopa/1077683 to your computer and use it in GitHub Desktop.
traitとtraitを合体させるテスト
<?php
trait Hello {
public function hello(){
echo "hello\n";
}
}
trait World {
public function world(){
echo "world\n";
}
}
trait HelloWorld {
use Hello, World;
public function helloWorld(){
$this->hello();
$this->world();
}
}
class Test {
use HelloWorld;
}
$test = new Test();
$test->helloWorld();
$test->hello();
$test->world();
?>
実行結果
hello //helloWorldメソッドの結果
world //
hello //Hello traitのメソッドも
world //World traitのメソッドも利用出来る
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment