このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
11_php:03_magic_constants [2014/12/15 06:19] – matsui | 11_php:03_magic_constants [2021/07/15 05:12] (現在) – matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 03 自動で定義済みの定数 ====== | ||
+ | 自動的に定義される定数(マジカル定数)が 8 つあります。 | ||
+ | |||
+ | ^ 名前 | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | | < | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | ===== 例1. ===== | ||
+ | |||
+ | < | ||
+ | <?php // | ||
+ | |||
+ | echo " | ||
+ | echo " | ||
+ | echo " | ||
+ | echo test_function(); | ||
+ | |||
+ | function test_function(){ | ||
+ | $res = ''; | ||
+ | $res .= " | ||
+ | return $res; | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | <code console> | ||
+ | $ php test_01.php | ||
+ | __LINE__ -> 3 | ||
+ | __FILE__ -> / | ||
+ | __DIR__ -> / | ||
+ | __FUNCTION__ -> test_function | ||
+ | </ | ||
+ | |||
+ | ===== 例2. ===== | ||
+ | < | ||
+ | <?php // | ||
+ | |||
+ | namespace My\Space; | ||
+ | |||
+ | $class = new TestClass; | ||
+ | |||
+ | $class-> | ||
+ | $class-> | ||
+ | $class-> | ||
+ | |||
+ | class TestClass { | ||
+ | |||
+ | function test_mess_01() { | ||
+ | echo " | ||
+ | } | ||
+ | function test_mess_02() { | ||
+ | echo " | ||
+ | } | ||
+ | function test_mess_03() { | ||
+ | echo " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code console> | ||
+ | $ php test_02.php | ||
+ | __CLASS__ -> My\Space\TestClass | ||
+ | __METHOD__ -> My\Space\TestClass:: | ||
+ | __NAMESPACE__ -> My\Space | ||
+ | </ | ||
+ | |||
+ | {{tag> php: |