Namespaces are declared using the namespace keyword. A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare keyword.
命名空间定义的php手册
是否可以给整个目录一个命名空间而不需要在每个单独文件的开头声明命名空间?
请您参考如下方法:
直接的答案是否定的。您可以为单个文件声明多个命名空间,但不能通过单行语句将单个命名空间声明为多个文件。您必须在每个文件中执行此操作。