Page 1 of 1

array of objects?

Posted: Tue Oct 11, 2005 12:30 am
by Ree
I do not like using this kind of iteration of db results like this (news items in the db):

Code: Select all

while ($row = $rs->nextRow())
{
  echo $row['headline'];
  echo $row['body'];
}
I would prefer putting all news items as objects in an array and then iterate over them like this:

Code: Select all

foreach ($items as $item)
{
  echo $item->getName();
  echo $item->getBody();
}
For me this would be more convenient, as I may also need to do some tricks with the data in the news item object (for example, do some replacing or any other string manipulation).

Is it ok to use object arrays? What if I have 500 objects in the array? Can this method become a performance hit?

Posted: Tue Oct 11, 2005 12:40 am
by feyd
generally it's fine.. my current project can often have over 1000 objects concurrently loaded and being processed. Our server has yet to complain at all about it.. :)