關(guān)鍵詞列表

這些詞語在 PHP 中有著特殊的意義。它們中有些像是函數(shù),有些像是常量,但是它們不是真的,它們只是語言結(jié)構(gòu)的一部分。不能使用它們的任何一個作為常量、類名、函數(shù)或方法名。但是它們可以被用作類的屬性、常量以及類的方法名,或者接口名和 traits 名,除了 class 不能被用作常量名。

PHP 關(guān)鍵詞
__halt_compiler() abstract and array() as
break callable case catch class
clone const continue declare default
die() do echo else elseif
empty() enddeclare endfor endforeach endif
endswitch endwhile eval() exit() extends
final finally fn (從 PHP 7.4 開始) for foreach
function global goto if implements
include include_once instanceof insteadof interface
isset() list() match (從 PHP 8.0 開始) namespace new
or print private protected public
readonly (as of PHP 8.1.0) * require require_once return static
switch throw trait try unset()
use var while xor yield
yield from        

* readonly may be used as function name.

編譯時常量
__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__
__NAMESPACE__ __TRAIT__