Jump to content

Recommended Posts

Which of these is the best way to program in PHP when usng classes? Please explain why and only answer if you are 100% sure, not just what you actualy do.

 

Example is for a site with 50 or so classes where 1 or 2 will be used per script.

 

(1) Use Autoloading Classes (function __autoload) for EVERY class you need (so you never need to define any classes).

 

(2) Just require_once every class every time (use one include file on the main .php page where a require_once is used for each of 50 classes inside this include file)

 

(3) Ensure every page/script has individual require_once('specificClass.php'); for each needed class for that page/script (slow when creating script of course and may miss some)

 

I like (1), but this seems like it could be wrong (and too easy!).

Link to comment
https://forums.phpfreaks.com/topic/207755-autoloading-classes/
Share on other sites

This is what the magic function __autoload is for. It will only include the necessary classes your code will require. However you can of course do this manually though. But there is no point including all classes and only using two or three at a time.

Link to comment
https://forums.phpfreaks.com/topic/207755-autoloading-classes/#findComment-1086060
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.