本教程以php为例,其实都是一样的
关键字列表
这些词在PHP中有特殊含义。它们中的一些表示看起来像函数的东西,一些看起来像常数,等等——但它们实际上不是:它们是语言结构。不能将下列任何单词用作常量、类名、函数或方法名。使用它们作为变量名通常是可以的,但可能会导致混淆。
从PHP 7.0.0开始,这些关键字可以作为类、接口和特征的属性、常量和方法名,但是类不能用作常量名。
__halt_compiler() | abstract | and | array() | as |
break | callable (as of PHP 5.4) | 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 (as of PHP 5.5) | for | foreach | function |
global | goto (as of PHP 5.3) | if | implements | include |
include_once | instanceof | insteadof (as of PHP 5.4) | interface | isset() |
list() | namespace (as of PHP 5.3) | new | or | |
private | protected | public | require | require_once |
return | static | switch | throw | trait (as of PHP 5.4) |
try | unset() | use | var | while |
xor | yield (as of PHP 5.5) |
PHP关键字必须小写。
PHP常量true、false和null必须小写。
正则查找关键字
1 | \b((a(bstract|nd|rray|s))|(c(a(llable|se|tch)|l(ass|one)|on(st|tinue)))|(d(e(clare|fault)|ie|o))|(e(cho|lse(if)?|mpty|nd(declare|for(each)?|if|switch|while)|val|x(it|tends)))|(f(inal|or(each)?|unction))|(g(lobal|oto))|(i(f|mplements|n(clude(_once)?|st(anceof|eadof)|terface)|sset))|(n(amespace|ew))|(p(r(i(nt|vate)|otected)|ublic))|(re(quire(_once)?|turn))|(s(tatic|witch))|(t(hrow|r(ait|y)))|(u(nset|se))|(__halt_compiler|break|list|(x)?or|var|while))\b |
利用正则可以在你的编写的代码里面查找是否使用了关键字