user282835
user282835

Reputation:

__autoload and including files

I have a site which uses the library file lib.client.php which is stored in the php folder in my standard website root and contains a series of classes I have built.

I am going to have to require_once this library file in almost every single page, what is the best way I can implement this? Furthermore, should I be using some conbination of functions using __autoload to accomplish this?

Having seen a very similar question which touches on the issue but offers a very specific answer I can't really use, and looking a bit into the __autoload function, I want to get a more detailed answer for my requirements.

Upvotes: 0

Views: 47

Answers (1)

fdreger
fdreger

Reputation: 12505

You use __autoload (or better: spl_autoload_register; or even better: some autoloader written by someone else) if:

  • you have many classes that are being used in different order in different files;
  • classes are spread across many files;
  • there is a strict way to tell which class is in which file.

In your case: just use require_once (or refactor, but I would not bother).

Upvotes: 1

Related Questions