PDA

View Full Version : PHP Objects vs Arrays


The Ace
04-30-2007, 09:06 AM
Hey,
I'm making a class that reads information from various sources,
and eventually needs to return an array of data, or an object.
that my question...

the array is filled with a number of items (at least one item).
I can't "change" the data (it's not stored on a database that i can access to and change), so all the returned data is static on my end.

any reason for me to use objects instead of regular arrays in that situation?

Thanks guys.

nikkiH
04-30-2007, 08:50 PM
Is an Array not an object in PHP?

iLLin
04-30-2007, 08:56 PM
I think hes talking using a class object. I think using a class instead of just a simple array is more organized. But if you using a class to capture all this static data then why not put it in a variable inside that class and call it?

$myClass->data['value1'];

Kinda hard to help when were just guessing.

Nimlhûg
04-30-2007, 10:00 PM
There's no real reason to create an object there, no. The fact that you mention that it can contain an undefined (but at least 1) number of items makes it sound like a good old fashioned array would be perfect for the job. The fact that you can't change the data in the database makes no real difference.

If you were to make an object out of it, all you'd end up with is an array to contain your items, and a method to get the data. Sounds like a waste of time to me.