tags:

views:

112

answers:

3

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 static methods?

Like:

MathGuru::calculateFoo($bar);

Would autoload load MathGuru here? Or must I include it manually?

+3  A: 

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

  • the autload 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 instanciate it or anything.

Pascal MARTIN
+3  A: 

Yes it would trigger __autoload.

It's not just 'new' that triggers autoloading - any reference to an unknown class will do it. Even something like using class_exists will trigger the autoloader (this isn't always desirable behaviour, which is why class_exists has a second parameter to disable autoloading)

Paul Dixon
+1  A: 

Surely the best, and fastest way is to try it?

From the docs there is nothing that mentions new being needed.

jakenoble