繁体   English   中英

无效为类名称部分的PHP关键字列表

[英]List of PHP Keywords that are Invalid as Class Name Parts

我正在为PHP 5.2转换一些用“穷人的命名空间”编写的旧代码

Foo_Bar_Model_Break_Baz类{}

我正在将此代码转换为需要真实名称空间的新系统,例如

namespace Foo\Bar\Model\Break;
class Baz
{
}

不幸的是,PHP解析器无法处理以上类,因为Break是保留字

Parse error: syntax error, unexpected 'Break' (T_BREAK), expecting identifier (T_STRING) in

在PHP完整类名/命名空间中,有哪些解析器标记无效的列表? 一些最初的谷歌搜索和php.net并没有打开任何东西,但是我可能使用了错误的搜索词。

在PHP 7中,这已通过添加Content Aware Lexer进行了更改。 该RFC将保留关键字的数量从64个减少到1个,其中一个特别是一个名为class的类常量(不区分大小写)。

要引用RFC,PHP <= 5.6.x中的全局保留关键字列表为:

callable  class  trait  extends  implements  static  abstract  final  public  
protected  private  const enddeclare  endfor  endforeach  endif  endwhile  and
global  goto  instanceof  insteadof  interface namespace  new  or  xor  try
use  var  exit  list  clone  include  include_once  throw  array print  echo  
require  require_once  return  else  elseif  default  break  continue  switch
yield function  if  endswitch  finally  for  foreach  declare  case  do  while
as  catch  die  self parent

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM