V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hheedat
V2EX  ›  PHP

Composer 的 Autoloader 为什么要这样写?

  •  
  •   hheedat · 2017-02-10 20:48:51 +08:00 · 2334 次点击
    这是一个创建于 2638 天前的主题,其中的信息可能已经有所发展或是发生改变。

    WX20170210-204118.png

    spl_autoload_register 了加载函数之后,只干了一件事就 spl_autoload_unregister 了,这是为何?

    为何不直接 require ,是有什么思想在里面吗?

    3 条回复    2017-02-10 22:21:19 +08:00
    holyghost
        1
    holyghost  
       2017-02-10 21:55:05 +08:00
    用来确保 $loader 是用 **自己的 method 的实现** require 进来的吧?最后一个参数是 true ,意思就是说先用老子的去找。

    既然找到了,就可以 unregister 了。
    hheedat
        2
    hheedat  
    OP
       2017-02-10 22:12:20 +08:00
    pubby
        3
    pubby  
       2017-02-10 22:21:19 +08:00
    @hheedat 看来不用 class_exists 判断再 require 是为了解决 APC 在高负载下的问题。
    不过现在都用内置 zend opcache 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2420 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:13 · PVG 08:13 · LAX 17:13 · JFK 20:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.