简体   繁体   中英

Namespace conflict. Own spl_autoload_register for different directories

I create own wordpress starter kit for plugins and themes.

I want use php namespaces in my projects (wp plugins and themes).

I set up spl_autoload_register function:

All is well. Until I create 2 projects based on my starter-kit. In this case, I get an error 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.

My structure:

在此处输入图片说明

How do I avoid name conflicts? And what can happen if someone else registers a function spl_autoload_register ?

How do I avoid name conflicts?

Use namespaces .

what can happen if someone else registers a function 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM