基本
| クラス名 |
__CLASS__ |
echo __CLASS__;
|
| 継承先で継承元の)クラス名 |
get_called_class() |
echo get_called_class();
|
| 関数名 |
__FUNCTION__ |
echo __FUNCTION__;
|
| 行数 |
__LINE__ |
echo __LINE__;
|
クラス名と関数名、行数を出力
echo __CLASS__ . '::' . __FUNCTION__ . '() - ' . __LINE__;
// 「〇〇〇::〇〇〇() - 〇〇〇」みたいな感じで出力
__CLASS__とget_called_class()
| __CLASS__ |
記述のあるクラス名 |
| get_called_class() |
呼び出したクラス名 |
class hoge {
public static function class_name() {
echo __CLASS__; // このコードのクラスである「hoge」
}
public static function called_class_name() {
echo get_called_class(); // 呼び出したクラス名
}
}
// =====
class foo extends hoge {}
// =====
hoge::class_name(); // 出力: hoge
hoge::called_class_name(); // 出力: hoge
foo::class_name(); // 出力: hoge
foo::called_class_name(); // 出力: foo