I think the answer to your question is "it doesn't really matter."
In terms of application performance, the code you are talking about - iterating through a loop in memory 50 times and manipulating data in memory, retrieving class data, or retrieving data from an associative array - is incredibly fast. So fast that it is almost impossible to measure differences under normal circumstances. To notice the difference between employee::$id, employee::$name
vs employee::$result['id'], employee::$result['name']
, you have to deal with extreme circumstances - an array of $ result from million columns, for example. See this criterion.
On the other hand, from a design point of view, there are some tradeoffs - by matching the result with class variables, you can hide the business logic and create a consistent interface. For example, if your employee class should calculate year_salary based on the month_salary database field, you can create another class variable called "year_salary" and the client code is always consistent - it is employee::annual_salary
and employee::monthly_salary
, not employee::result['monthly_salary']
and employee::annual_salary
.
source share