[英]Namespace conflict. Own spl_autoload_register for different directories
I create own wordpress starter kit for plugins and themes. 我为插件和主题创建了自己的wordpress入门套件。
I want use php namespaces in my projects (wp plugins and themes). 我想在我的项目中使用php名称空间(wp插件和主题)。
I set up spl_autoload_register
function: 我设置了
spl_autoload_register
函数:
All is well. 一切都很好。 Until I create 2 projects based on my starter-kit.
直到我根据入门工具包创建了2个项目。 In this case, I get an error
Cannot redeclare class ...
. 在这种情况下,我收到一个错误,
Cannot redeclare class ...
All plugins and themes are in separate directories. 所有插件和主题均位于单独的目录中。 And in each such folder there is my starter kit with
spl_autoload_register
function. 在每个这样的文件夹中,都有我的带有
spl_autoload_register
函数的入门工具包。
My structure: 我的结构:
How do I avoid name conflicts? 如何避免名称冲突? And what can happen if someone else registers a function
spl_autoload_register
? 如果其他人注册了函数
spl_autoload_register
会发生什么?
How do I avoid name conflicts?
如何避免名称冲突?
Use namespaces . 使用名称空间 。
what can happen if someone else registers a function
spl_autoload_register
?如果其他人注册了函数
spl_autoload_register
会发生什么?
When it needs to use a class that is not declared, the interpreter invokes the autoload functions registered using spl_autoload_register
one by one in the order they were registered until the class becomes available. 当需要使用未声明的类时,解释器
spl_autoload_register
注册顺序依次调用使用spl_autoload_register
注册的自动加载函数,直到该类可用为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.