Last active
December 14, 2015 21:39
-
-
Save hirak/5152651 to your computer and use it in GitHub Desktop.
PHP5.2で遅延静的束縛 ref: http://qiita.com/Hiraku/items/2f4e3c146857010b4ff6
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 | |
function doSomething($hoge=__LINE__) { | |
var_dump($hoge); | |
} |
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 | |
class A { | |
static function hoge() { | |
var_dump(get_called_class()); | |
} | |
} | |
class B extends A {} | |
class C extends B {} | |
A::hoge(); //A | |
B::hoge(); //B | |
C::hoge(); //C | |
//staticメソッドで、どのクラスのメソッドとして呼ばれたか判定が可能 |
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 | |
class A { | |
static function hoge($class=__CLASS__) { | |
var_dump($class); | |
} | |
} | |
class B extends A { | |
//派生クラスには以下のコードをコピペする | |
static function hoge($class=__CLASS__) { | |
return parent::hoge($class); | |
} | |
} | |
class C extends B { | |
//派生クラスには以下のコードをコピペする | |
static function hoge($class=__CLASS__) { | |
return parent::hoge($class); | |
} | |
} | |
A::hoge(); //A | |
B::hoge(); //B | |
C::hoge(); //C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment