dqc19941228 2015-06-22 12:32
浏览 33
已采纳

在同一运行时中两次使用一个命名空间

I have two separate PHP modules each containing a vendor folder created by composer. Both modules use the composer autoloader which is registered before any of the module's class is instantiated.

Each vendor folder contains a different version of Doctrine, so in the same runtime, if I instantiate any Doctrine class from one module, any subsequent calls to the same Doctrine class from the other module, will use the first instantiated class as it is already autoloaded by PHP (it has same namespace, same name).

Is there a way to go around this without actually renaming all the namespaces and use declarations of one or both of the different Doctrine libraries?

  • 写回答

1条回答 默认 最新

  • dongzhazhuo0572 2015-06-22 17:12
    关注

    No, there is no way to use two versions of the same classes in one runtime. This is independent of autoloading, it's PHP basics:

    If a class of name "X" is defined, no autoloading will trigger to load it again. And it cannot be included a second time manually because that will result in an error (classes, as well as functions, can only be declared once).

    Try not to use two different versions of Doctrine. The best solution would be to add both your PHP modules to the main application using Composer itself. That way, both modules would declare their dependencies (among them Doctrine), and Composer would try to load the best possible version - but only ONE version. If this is impossible because of incompatible version constraints, you will know and then have to update your code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题