Assume we have some object
$a = new stdClass;
$a->b = 7;
$a->c = 'o';
$a->d = array(1,2,3);
Also we have a function which doing something with some of properties of our object (for example b and d[1]).
My question: Should my function accept whole object as a parameter like:
function some($a) {
var_dump($a->b);
var_dump($a->d[1]);
}
some($a);
or accept only certain fields which it’s process like:
function some($b, $d) {
var_dump($b);
var_dump($d);
}
some($a->b, $a->d[1]);
Actually no matter is $a object or array.
I believe the first option is the way to go.
Because maybe over time you will need other parts of that object/array and you will have to modify the function and the calls where you make them.
So
function some()can be a global function and used in other ways, you can add later statements, modify the function without having to modify everywhere.