Hello everyone,
I'm taking my first steps in PHP programming and now it's time for my first 'real project'. Rather than code everything in the (few) pages I have to create - I'm thinking of using a Object Oriented approach.
My question is where should I keep my classes? I saw somewhere an example where the classes were all put in a single fleh.inc file and included at the start of each page.
I guess I might create something like 10 classes and am wondering if I should have them all in one file and include it in all my pages - or if I should group them together in 5 files (or so) and include only those containing classes that I'll need for each page.
NB. I haven't started any real design yet, the project is still only in my head but I'd appreciate tips on how you'd do this.
The balance in my mind being between simple coding and minimal load on the server. Does it affect the server noticably to include uneccesary lines of code?
Any suggestions?
Thanx, Toro
Classes: how best to connect them to other code?
Moderator: General Moderators
Whatever you decide for your classes, please don't use a .inc file. If someone is lucky they may stumble across the file and their browser will ask if they wish to download the file, should it contain database login details or other vital info you could be in do-do. Give the file a .php extension and the browser will just show a blank page.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Yeah definitely don't use .inc extensions for any of your PHP pages (unless the server has been set up to parse .inc as PHP). You can always use filenames like myclass.class.php, myclass2.class.php instead.
Also try to keep each class in a separate file and only include those you need using include_once().
Check out this thread for a discussion on OOP and PHP:
http://www.devnetwork.net/forums/viewtopic.php?t=1089
Enjoy your programming.
Mac
Also try to keep each class in a separate file and only include those you need using include_once().
Check out this thread for a discussion on OOP and PHP:
http://www.devnetwork.net/forums/viewtopic.php?t=1089
Enjoy your programming.
Mac