Created
July 12, 2011 09:34
-
-
Save kamekoopa/1077683 to your computer and use it in GitHub Desktop.
traitとtraitを合体させるテスト
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 | |
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