Class/Object Naming Convention

I'm trying to decide on the best approach to something.

I have a "while { }" loop going - and grabbing values from a class.  The resulting data needs to be grouped together by something or other.  So I'm trying to decide if I want to store all of the values into a singular object that contains all groups and all values - or spawn a new object for each grouping.

I'm inclined to go for the latter and think that's a better idea...  where each object is unique with it's own associated properties.

The question I have is about proper naming convention.  

say I had a thing like...

while ($i < 100) {
$rateobj = new DayRate;
$i++
}

and I wanted $rateobj to be instantiated with $i as part of the name?

Would it be $rateobj.i = new DayRate

?
LVL 2
erzoolanderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
An array of objects is a very useful data construct.  You can put the $i value into the object, or use it as the key of the array (or both) but it would be something of an anti-practice to make it part of the name.  If it were up to me I might do something like this.
http://iconoun.com/demo/temp_erzoolander.php
<?php // demo/temp_erzoolander.php

/**
 * See http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28657938.html
 */
error_reporting(E_ALL);
echo '<pre>';

Class DayRate {}

$dayrates = array();
for ($i = 0; $i < 5; $i++)
{
    // CREATE AN OBJECT AND PLUG IN SOME DATA
    $x = new DayRate;
    $x->kount = $i;

    // ADD THE OBJECT TO THE ARRAY OF OBJECTS
    $dayrates[$i] = $x;
}

// SHOW WHAT WE CREATED
var_dump($dayrates);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erzoolanderAuthor Commented:
Gracias!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.