hheedat
V2EX  ›  PHP

Composer 的 Autoloader 为什么要这样写?

  •  
  •   hheedat · Feb 10, 2017 · 2768 views
    This topic created in 3379 days ago, the information mentioned may be changed or developed.

    WX20170210-204118.png

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

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

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

    既然找到了,就可以 unregister 了。
    pubby
        3
    pubby  
       Feb 10, 2017
    @hheedat 看来不用 class_exists 判断再 require 是为了解决 APC 在高负载下的问题。
    不过现在都用内置 zend opcache 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5544 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 165ms · UTC 08:36 · PVG 16:36 · LAX 01:36 · JFK 04:36
    ♥ Do have faith in what you're doing.