Passing class names or objects?
- by nischayn22
I have a switch statement
switch ( $id ) {
case 'abc': return 'Animal';
case 'xyz': return 'Human';
//many more
}
I am returning class names,and use them to call some of their static functions using call_user_func().
Instead I can also create a object of that class, return that and then call the static function from that object as $object::method($param)
switch ( $id ) {
case 'abc': return new Animal;
case 'xyz': return new Human;
//many more
}
Which way is efficient?
To make this question broader : I have classes that have mostly all static methods right now, putting them into classes is kind of a grouping idea here (for example the DB table structure of Animal is given by class Animal and so for Human class). I need to access many functions from these classes so the switch needs to give me access to the class