This is a discussion on Object or Array?? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello there... I have a little issue here.... Which one is better(I think object) but would like to hear ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello there...
I have a little issue here.... Which one is better(I think object) but would like to hear from someone more experienced.... class Persons { var $name; var $comments; var $thoughts; var $email; some functions..... } object in array: while($line = $result->FetchRow()) //using ADODB { $person[$line['id']] = &new Persons; $person[$line['id']]->name = $line['name']; $person[$line['id']]->thoughts = $line['thoughts']; $person[$line['id']]->email = $line['email']; $person[$line['id']]->comments = $line['comments']; } or plain array: while($line = $result->FetchRow()) $person[$line['id']]=Array("name"=>$line['name'],"thoughts"=>$line['thoughts '],"email"=>$line['email'],"comments"=>$line['comments']); thanx and respect.... p. |
|
|||
|
point wrote:
> Hello there... > > I have a little issue here.... > > Which one is better(I think object) but would like to hear from someone more > experienced.... I would go for objects, if you are using functions that are specific for the data within the object. //Aho |
|
|||
|
point wrote:
> Hello there... > > I have a little issue here.... > > Which one is better(I think object) but would like to hear from someone > more experienced.... > > class Persons > { > var $name; > var $comments; > var $thoughts; > var $email; > > some functions..... > } > > object in array: > > while($line = $result->FetchRow()) //using ADODB > { > $person[$line['id']] = &new Persons; > $person[$line['id']]->name = $line['name']; > $person[$line['id']]->thoughts = $line['thoughts']; > $person[$line['id']]->email = $line['email']; > $person[$line['id']]->comments = $line['comments']; > } > > or plain array: > > while($line = $result->FetchRow()) > > $person[$line['id']]=Array("name"=>$line['name'],"thoughts"=>$line['thoughts > '],"email"=>$line['email'],"comments"=>$line['comments']); > > thanx and respect.... I rather like the syntax of objects, and usually a row in a well-designed database corresponds to "something I naturally think of as 'a thing.'" So I think of them as objects and use them that way. Also, as other people have observed, these same 'things' usually have some sort of method (i.e. it's not a database field, but something that I'm computing based on it or doing to it) that I want to "do with it." It's also rather nice when you define your objects as descending from a basic class that "knows how to handle a database." It keeps you from putting a lot of database-specific code all over your application: the less repetition there is, the less you have to change! (And, debug!!) |
|
|||
|
"point" <point@caanNOSPAMproduction.com> wrote
in message news:<bjev3q02vgv@enews2.newsguy.com>... > > Which one is better (I think object) but would like to hear > from someone more experienced.... Define "better". Better for what? Reusability? Go with objects. Performance? Stick with arrays and stop using abstraction layers. Cheers, NC |
|
|||
|
Thanx for your oppinions....
I'm sticking with objects just wanted to hear your oppinions.... In my oppinion objects are more close(although more abstract) to human way of thinking than the procedural programing..... respect.... "point" <point@caanNOSPAMproduction.com> wrote in message news:bjev3q02vgv@enews2.newsguy.com... > Hello there... > > I have a little issue here.... > > Which one is better(I think object) but would like to hear from someone more > experienced.... > > class Persons > { > var $name; > var $comments; > var $thoughts; > var $email; > > some functions..... > } > > object in array: > > while($line = $result->FetchRow()) //using ADODB > { > $person[$line['id']] = &new Persons; > $person[$line['id']]->name = $line['name']; > $person[$line['id']]->thoughts = $line['thoughts']; > $person[$line['id']]->email = $line['email']; > $person[$line['id']]->comments = $line['comments']; > } > > or plain array: > > while($line = $result->FetchRow()) > > $person[$line['id']]=Array("name"=>$line['name'],"thoughts"=>$line['thoughts > '],"email"=>$line['email'],"comments"=>$line['comments']); > > thanx and respect.... > > p. > > > > |