Object or Array??

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-07-2003
point
 
Posts: n/a
Default Object or Array??

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.




Reply With Quote
  #2 (permalink)  
Old 09-07-2003
J.O. Aho
 
Posts: n/a
Default Re: Object or Array??

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

Reply With Quote
  #3 (permalink)  
Old 09-07-2003
Sundial Services
 
Posts: n/a
Default Re: Object or Array??

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!!)




Reply With Quote
  #4 (permalink)  
Old 09-07-2003
Nikolai Chuvakhin
 
Posts: n/a
Default Re: Object or Array??

"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
Reply With Quote
  #5 (permalink)  
Old 09-08-2003
point
 
Posts: n/a
Default Re: Object or Array??

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.
>
>
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:36 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0