Created
December 8, 2022 04:54
-
-
Save fumikito/21d76ac94e59fc51c428c2d65125d42c to your computer and use it in GitHub Desktop.
Revisions
-
fumikito created this gist
Dec 8, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ <?php trait BaseTrait { private $counter = 0; private $greeting = 'Hello World!'; public function say_hello() { $this->counter++; echo $this->greeting . PHP_EOL; } public function greet_count() { printf( 'Greeted %d times' . PHP_EOL, $this->counter ); } } trait John { use BaseTrait; public function john() { echo 'Hi, john. '; $this->say_hello(); } } trait Lisa { use BaseTrait; public function lisa() { echo 'Hi, Lisa! '; $this->say_hello(); } } class Me { use John, Lisa; public function greet() { $this->john(); $this->lisa(); $this->greet_count(); } } $me = new Me(); $me->greet(); // ここで$countは2になっているべき