[英]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.