I'm hoping someone can help me with some design thinking.. I'm still fairly new to php and most of my scripts are written in a rather procedural format. I'd like to try start thinking in a more object-oriented way. The
There's no reason why you *have* to use objects. Heck OOP isn't necessary in the least, especially in a web environment where it is likely you are going to be changing things around a lot. ;)
That being said: if you *do* decide that organizing your code into objects is what you want to do is try to use objects to model things in the simplest way possible. KISS = Keep It Simple Stupid. No offense intended to you, it's what I say to myself also :)
For example if you want one of the object's methods to produce error messages well that's great... but don't echo it to the screen. You might later instead decide that you want to log the errors into a file (when you move a script into production).
piece I'm working on is rather simple but I'm not sure how to arrange things. Basically, I'm making a list of users for a message board and when the list is displayed, it looks similar to the following:
Add User <http://>
| ID | Name | Homepage | Action |
---------------------------------------------------------------------------- ---------
1 User1 http://... Edit <http://>
| Delete <http://>
2 User2 http://... Edit <http://>
| Delete <http://>
3 User3 http://... Edit <http://>
| Delete <http://>
..
I'd like to be able to do things like:
$obj = new member;
$obj->firstname = "Tim";
$obj->homepage = "www.myhomepage.com";
$obj->saveuser();
Or
$obj->deleteuser($id);
Or
$obj->getuser($id);
I'm not sure if I should include database functionality to this object or if I should separate it to a database class.
As stated above: keep objects as simple as possible to give you some flexibility to use them in the future. The PEAR::DB classes are built so that you can move from one database to another with relative ease. So by using a seperate DB object you are able to plug in a new database instead of oracle / mysql / whatever (should the need ever arise).
Harry Fueck's website http://phppatterns.com/ is a good place to start learning about objects in PHP.
Are there any good examples of doing things like this? I've got the O'reilly book called PHP Cookbook and I was playing with the example on page 159, example 7.8..because they start out with what looks like the PEAR DB and that's what I'm using.
Any thoughts and/or help with this would be greatly appreciated
TIA!
Jim
-- Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://www.php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY | http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php