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

前端 未结 6 1376
耶瑟儿~
耶瑟儿~ 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:33

    I had one issue with this where a very minor syntax error gave a pretty unclear error message where it looked like __autoload() wasn't being called.

    SomeClass:callStaticMethod(); // Doesn't call autoload for "SomeClass"
    
    SomeClass::callStaticMethod(); // Successfully calls autoload for "SomeClass"
    

    PHP strangely interprets the single ":" (instead of the correct double "::") as nothing. It treats callStaticMethod() as a global method call, meaning it skips the __autoload.

提交回复
热议问题