I have some input that I send to a computational library, which processes the input and produces some output.
Question: What considerations do I take into account to help me decide whether the output data type should be an array, or an object? Similarly the same can apply to an Input object that's fed into the library.
$t = array(); $t['number_of_shells'] = 3; $t['shell_length'] = 2.51; $t['pipe_model'] = 2.38;
$t = OutputObject(); $t->setNumberOfShells(3); $t->setShellLength(2.51); $t->setPipeModel(2.38);
Where it will be used
In my immediate case, this structure will be used to accumulate some data from several various sources (computational library, database, pass-through-input) and then passed to the
View layer, where it will be plugged into placehodlers of the view template.
From where I see it, arrays are easier to create, easier to maintain, as in my case all I need is basically values. Objects are more robust in that they hardcode the available values into properties and there is less of a chance of making a typo. But they also add some overhead.
I will use the data structure as a return type of the computational library, and later use it for data to feed to my View layer, or to my Unit Test suite.