Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top