What are the valid characters in PHP namespace names?

What rules should my namespace names follow?

+6
source share
1 answer

Variable names follow the same rules as other labels in PHP. A valid variable name begins with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, this would be expressed as follows: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

http://php.net/manual/en/language.variables.basics.php

β€œOther labels” here refer to namespaces, among other things, like class and function names.

Please note that PHP does not have its own understanding of encodings and considers labels like simple byte arrays; most Unicode strings (read: UTF-8) satisfy the above naive regex:

 // yup, works namespace ζΌ’ε­—; class ζ–‡ε­— {} 
+8
source

Source: https://habr.com/ru/post/1012985/


All Articles