PHP spl_autoload practise with static functions

110 views Asked by At

I'm using an autoload for my classes such as:

function my_autoloader($Class){
  // classes
  include "class/Class_User.php";

  // helpers
  include "helper/Url_Helper.php";

  }

spl_autoload_register('my_autoloader');

All is working great however I have some question. The content of Url_Helper is not a class, there are just a classic php functions I use across the site. The functions in Url_Helper are accessible only AFTER I initiate some (any) class like: $User = new User();

After this the functions get loaded. But if I call a function from Url_Helper and do not use any class at all it doesn't get loaded.

Can you explain me a little bit what's going on in here?

1

There are 1 answers

4
Gerben Jacobs On BEST ANSWER

You already debugged it. You say when you load no class, the helpers don't get loaded; this is true. If you want your helpers always to be available, you should include them outside of your autoload function.