Depends ;-) I'd say that the second way is probably "best", becuase it avoids implied behaviour, which sometimes can cause problems (lets say you want to init. a document object, but not get anything from the DB). If you want to create a brand new Document, obviously it won't be in the DB already, so you might not want to have the constructor go and try to fetch it.
instead (with option #2), you could do something like: // Create new document $d = new Document(); // populate document $d->save(); and // Get existing doc $d = new Document(); $d->get(ID); But that's just my view... there are as many different views on OO as there are programmers :) --- Scott Hurring Systems Programmer EAC Corporation [EMAIL PROTECTED] Voice: 201-462-2149 Fax: 201-288-1515 > -----Original Message----- > From: Henry Blackman [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, June 05, 2002 5:33 PM > To: [EMAIL PROTECTED] > Subject: [PHP] OOP Question in PHP > > > Hello. > > I have, what is probably a silly, question. > > I want to convert my existing scripts to OO - because it's > the "way to go" > in terms of the huge amount of functionality that they now > have (and since > I've never done it before it would be interesting). However > I have one > thing that I don't understand. > > My scripts manipulate documents and these documents are > stored in a MySQL > database. > > To create a new object is really easy. However, since I have lots of > documents already, how do I alter one? > > Do I create a new document and pass the primary key as it's a > variable in > the > > $document = new Document(number); > > and have the constructor retrieve the appropriate data from > MySQL and fill > the attribute variables. > > Or do I do something like: > > $document = new Document; > $document ->retrieve(number); > > Which is the best and most "valid" way of doing things. > > Cheers, > Henry > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php