• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

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

?
0
erzoolander
Asked:
erzoolander
1 Solution
 
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
 
erzoolanderAuthor Commented:
Gracias!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now