PHP 命名空间中允许使用保留关键字吗? (public,私有,默认)
PHP reserved keywords allowed in namespace? (public, private, default)
PhpStorm 将以下命名空间突出显示为错误。
<?php
namespace App\Http\Controllers\Public;
错误:Expected: identifier
一般。 public
、function
、class
等保留关键字是否不能用于命名空间?
PHP manual 暗示从 PHP 7.0.0 开始,这些关键字被允许作为 属性、常量和 classes 的方法名称、接口和特征, 除了 class 不能用作常量名称 外,它还包含请求的关键字 public
.
不能用于命名空间的保留关键字列表:
__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
, for
, foreach
, function
, global
, goto
, if
, implements
, include
, include_once
, instanceof
, insteadof
, interface
, isset
, list
, namespace
, new
, or
, print
, private
, protected
, public
, require
, require_once
, return
, static
, switch
, throw
, trait
, try
, unset
, use
, var
, while
, xor
解决此问题的潜在解决方法是向单词添加一个额外的字符或使用单词的复数形式。另一个机会是在命名空间中上一级并使用关键字作为前缀 PublicFooController
。 (或者甚至是后缀,如果您愿意的话)
我的意图是将我的网络应用程序的范围限定为 public
(供客人和访客使用)和 private
(供私人需要)区域。
我选择了 namespace App\Http\Controllers\Frontend
和 namespace App\Http\Controllers\Backend
而不是尝试将 public
和 private
这两个词合并到我的命名空间中,即使我个人认为这些通常更适合我的需要,因为两者都有前端和后端。但是...无论如何,当我使用 public
和 private
.
时,这使我不会像以前那样组织文件和命名空间时遇到麻烦
PhpStorm 将以下命名空间突出显示为错误。
<?php
namespace App\Http\Controllers\Public;
错误:Expected: identifier
一般。 public
、function
、class
等保留关键字是否不能用于命名空间?
PHP manual 暗示从 PHP 7.0.0 开始,这些关键字被允许作为 属性、常量和 classes 的方法名称、接口和特征, 除了 class 不能用作常量名称 外,它还包含请求的关键字 public
.
不能用于命名空间的保留关键字列表:
__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
, for
, foreach
, function
, global
, goto
, if
, implements
, include
, include_once
, instanceof
, insteadof
, interface
, isset
, list
, namespace
, new
, or
, print
, private
, protected
, public
, require
, require_once
, return
, static
, switch
, throw
, trait
, try
, unset
, use
, var
, while
, xor
解决此问题的潜在解决方法是向单词添加一个额外的字符或使用单词的复数形式。另一个机会是在命名空间中上一级并使用关键字作为前缀 PublicFooController
。 (或者甚至是后缀,如果您愿意的话)
我的意图是将我的网络应用程序的范围限定为 public
(供客人和访客使用)和 private
(供私人需要)区域。
我选择了 namespace App\Http\Controllers\Frontend
和 namespace App\Http\Controllers\Backend
而不是尝试将 public
和 private
这两个词合并到我的命名空间中,即使我个人认为这些通常更适合我的需要,因为两者都有前端和后端。但是...无论如何,当我使用 public
和 private
.