Does the PHP autoloader function also work with static method calls?

前端 未结 6 1381
耶瑟儿~
耶瑟儿~ 2020-12-17 08:53

I slightly remember that autoload worked with the new statement. Now how about when I have several utility classes and I want to autoload these? And I only use

6条回答
  •  误落风尘
    2020-12-17 09:40

    The autoloading mechanism works exactly the same way with static classes that it does with non-static one :

    • The autoload function/method you registered will be called
    • It'll receive the name of the class
    • And it'll have to require/include the necessary PHP code


    Actually, the autoloader doesn't even have to "know" if it is called to load a static or a dynamic class, as its role is to load the PHP code that contains the class' definition -- and not instantiate it or anything.

提交回复
热议问题