PHP ?? ??
PHP? ???? ?? ????? ?? ??? ??? ??? ?????.
??? ?? ??? ??? ?? ?????? ?? ???? ??? ?? ?????? ????? ?? ?? ?? ?? ??? ?? ??? ???? ?????.
????? ??? ?? ?? ??? 8?? ?? ??? ????.
| ??? ?? ? ?????. | ||||||||||
? > ?>?> ?>?> ?>?> ?>?> __FILE__?> | < td width="193" valign="top" style="border-width: 1px; border-style: solid; word-break: break-all;">?>??? ?? ?? ? ?? ?????. ??? ?? ??? ???? ?? ??? ??? ??? ?????. ?>PHP 4.0.2?? __FILE__?? ?? ?? ??(??? ??? ?? ??? ?? ??)? ???? ??? ? ?? ???? ??? ?? ??? ???? ?????. |||||||||||
? > ?>?> ?>?> ?>?> __DIR__?> | ?>??? ??? ???????. ??? ?? ??? ???? ?? ??? ??? ?? ????? ?????. ?>?>dirname(__FILE__)? ?????. ???? ??? ?? ????? ?? ?? ?? ???? ???? ????. (PHP 5.3.0? ??? ??) ?> | ||||||||||
?> ?>?> ?>?> __FUNCTION__?> | ?? ??(PHP 4.3.0? ?? ???) PHP 5?? ? ??? ??? ?? ?? ??? ?????(???? ??). PHP 4??? ? ?? ?? ??????. | ||||||||||
? > ?>?> __CLASS__ ?> | ??? ??(PHP 4.3.0? ??? ??). PHP 5?? ? ??? ???? ????? ? ???? ??? ?????(???? ??) |
__TRAIT__ | Trait 的名字(PHP 5.4.0 新加)。自 PHP 5.4.0 起,PHP 實(shí)現(xiàn)了代碼復(fù)用的一個(gè)方法,稱(chēng)為 traits。 |
__METHOD__ | 類(lèi)的方法名(PHP 5.0.0 新加)。返回該方法被定義時(shí)的名字(區(qū)分大小寫(xiě))。 |
__NAMESPACE__ | 當(dāng)前命名空間的名稱(chēng)(區(qū)分大小寫(xiě))。此常量是在編譯時(shí)定義的(PHP 5.3.0 新增)。 |
??? ?? ? ??? ??? ??? ?????.
????
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 echo '這是第 “ ' . __LINE__ . ' ” 行'; ?>???? ?? ??:
??? "3" ?
__FILE__??? ?? ?? ? ?? ?????. ??? ?? ??? ???? ?? ??? ??? ??? ?????.
PHP 4.0.2?? __FILE__?? ?? ?? ??(??? ??? ?? ??? ?? ??)? ???? ??? ?? ???? ???
?? ??? ???? ?????. .
Instance<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 echo '該文件位于 “ ' . __FILE__ . ' ” '; ?>???? ?? ??:
?? ??? "D: WWW11.php ”
__DIR__
??? ?? ???????. ??? ?? ??? ???? ?? ??? ??? ?? ????? ?????.
dirname(__FILE__)? ?????. ???? ??? ?? ????? ?? ?? ?? ???? ???? ????. (PHP 5.3.0? ??? ??)
Instance
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 echo '該文件位于 “ ' . __DIR__ . ' ” '; ?>???? ?? ??:
? ?? ?? " D:WWW " ??? ?????(PHP 4.3.0? ??? ??). PHP 5?? ? ??? ??? ?? ?? ??? ?????(???? ??). PHP 4??? ? ?? ?? ??????.
????
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 function funtext() { echo '函數(shù)名為:' . __FUNCTION__ ; } funtext(); ?>
???? ?? ??:
?? ??? funtext
__CLASS__
???.??? ??(PHP 4.3.0? ??? ??). PHP 5?? ? ??? ????? ? ???? ??? ?????(???? ??).
PHP 4?? ? ?? ?? ??????. ??? ???? ???? ??? ??(?: FooBar)? ?????. PHP 5.4?? __CLASS__? ???? ?????. ?? ??? ??? ???? ?? __CLASS__? ?? ???? ???? ???? ?????.
Instance
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 class classtest { function fun() { echo '類(lèi)名為:' . __CLASS__ . "<br>"; echo '函數(shù)名為:' . __FUNCTION__ ; } } $t = new classtest(); $t->fun(); ?>
???? ?? ??:
??? ?? For: classtest?? ??? fun
__TRAIT__?? ??(PHP 5.4.0? ?? ???)???. PHP 5.4.0?? PHP? ????? ?? ??? ??? ?????. ?? ???? ??? ??(?: FooBar)? ?????. ?? ????? ??? ??? ??? SayWorld Trait? MyHelloWorld ???? ?? ??????. ?? ??? MyHelloWorld ???? ??? ???? ?????. ?? ??? ?? ???? ???? ?? ???? ?????, ?? ???? ?? ???? ???? ????? ????.
Instance
<?php class Base { public function sayHello() { echo 'Hello '; } } trait SayWorld { public function sayHello() { parent::sayHello(); echo 'World!'; } } class MyHelloWorld extends Base { use SayWorld; } $o = new MyHelloWorld(); $o->sayHello(); ?>
???? ?? ??:
Hello World!
__METHOD__
???? ??? ??(PHP 5.0) .0 ?? ???). ??? ?? ???? ??? ?????(???? ??).
<?php header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 function test() { echo '函數(shù)名為:' . __METHOD__ ; } test(); ?>
???? ?? ??:
?? ??: test
__NAMESPACE__
?? ??????? ?????(???? ??). ? ??? ??? ??? ?????(PHP 5.3.0? ??? ??).<?php namespace MyProject; header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 echo '命名空間為:"', __NAMESPACE__, '"'; // 輸出 "MyProject" ?>???? ?? ??:
??????? "MyProject"???.