Created
July 12, 2011 10:15
-
-
Save kamekoopa/1077727 to your computer and use it in GitHub Desktop.
traitをuseしたクラスを継承してみるテスト
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; | |
} | |
class TestChild extends Test{ | |
} | |
$test = new TestChild(); | |
$test->helloWorld(); | |
$test->hello(); | |
$test->world(); | |
?> | |
/* 出力 親クラスでuseしたtraitは小クラスでも使える */ | |
hello | |
world | |
hello | |
world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment