Handling array passed to object at creation

Posted by cecilli0n on Programmers See other posts from Programmers or by cecilli0n
Published on 2014-01-29T23:42:53Z Indexed on 2014/05/31 21:57 UTC
Read the original article Hit count: 238

Filed under:
|
|
|
|

When creating my object I pass it an array of a row from my database. (everything in the array we will need, disregarding unnecessary elements at sql query level)

When I need to access certain array elements from within my class, I do so like

$this->row['element']

However, As I continue development, I sometimes forget what exactly is in this passed array.(this itself doesn't seem good)

I am wondering if their is a professional approach to dealing with this, Or am I the only one who has these "I wonder whats in the array" thoughts.

One approach to tackling this could be that when we originally pass the array, in the constructor, we assign each element of the array to its own variable, but is this considered professional practice?

Additionally by doing this, we could make those variables constants, in a attempt at immutability.

Overall I am trying to adhere to good software craftsmanship.

Regards.

© Programmers or respective owner

Related posts about php

Related posts about object-oriented