Last active
April 26, 2016 10:53
-
-
Save matsu-chara/bc4ebfaa3e3e61470c8f7705cff5ad9c to your computer and use it in GitHub Desktop.
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 characters
<?php | |
abstract class Mofu { | |
abstract function isNyan(); | |
public function mofureyo() { | |
if($this->isNyan() === true) { | |
return "mofure"; | |
} else { | |
return "mofuruna"; | |
} | |
} | |
} | |
trait Nyan { | |
function isNyan() { | |
return true; | |
} | |
} | |
class MofuImpl extends Mofu { | |
use Nyan; | |
} | |
echo "普通のコード\n"; | |
$mofu = new MofuImpl(); | |
echo $mofu->mofureyo()."\n"; | |
trait MockNyan { | |
function isNyan() { | |
return false; | |
} | |
} | |
class MockMofuImpl extends Mofu { | |
use MockNyan; | |
} | |
echo "テストコード\n"; | |
$mofu = new MockMofuImpl(); | |
$mofu->isNyan(); | |
echo $mofu->mofureyo()."\n"; | |
// in PHP7 | |
// $nyan = new class { use Nyan; }; | |
class TestNyan { | |
use Nyan; | |
} | |
$nyan = new TestNyan(); | |
echo $nyan->isNyan()."\n"; |
Author
matsu-chara
commented
Apr 26, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment