我的命名空间名称必须遵循哪些规则?
最佳答案
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus:
[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
这里的“其他标签”确实指的是 namespace 以及类和函数名称等其他内容。
请注意,PHP 对编码没有 native 理解,并将此类标签视为纯粹的字节数组;大多数 Unicode 字符串(读取:UTF-8)将满足上述朴素的正则表达式:
// yup, works
namespace 漢字;
class 文字 {}
关于php - PHP 命名空间名称中的有效字符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41027816/