Page 1 of 1

Classes: how best to connect them to other code?

Posted: Wed Jul 03, 2002 8:03 am
by toro
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

Posted: Wed Jul 03, 2002 8:18 am
by martin
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.

Posted: Wed Jul 03, 2002 8:49 am
by twigletmac
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

Posted: Wed Jul 03, 2002 10:39 am
by toro
Thanks guys,
this answers my questions. Now I just have to find me some spare time to start coding and then I'll probably have more questions.

Cheers,
Toro