0

I would like to ask if it's better to pass a complete array or object to view or just a required value?

For example, controller is rendering some view which needs 2 parameters:

client.id and client.name

and now, will it have a big impact on the speed performance if I will pass complete client object (can have lots of data) or not at all?

undefinedman
  • 620
  • 1
  • 11
  • 25

2 Answers2

2

When You passing an object in reality you pass reference to it and it has 32bits size.

So if You alredy have object crated and You just need to pass some of its values to view better to pass its reference instead of only required values, You will crate just one new variable instead of x.

Gustek
  • 3,680
  • 2
  • 22
  • 36
0

@Gustek it's right, but arrays works by reference too. I made some test with kohana codebench a few years ago, and process data is more efficient in arrays than objects. A good coder would pass required values only...

rernesto
  • 554
  • 4
  • 11
  • http://stackoverflow.com/questions/2030906/are-arrays-in-php-passed-by-value-or-by-reference – Darragh Enright Nov 08 '13 at 21:18
  • A good coder avoids the use of the term "always". The controller should not need to know the details of what the view is doing. Pulling out individual values in the controller is (in general) a poor programming practice which would require updating the controller if the view decides it needs something like client.email. – Cerad Nov 09 '13 at 14:55
  • JeJe, relative to environment, we "ALWAYS" buy flexibility selling performance. – rernesto Nov 11 '13 at 13:48