Passing class names or objects?
Posted
by
nischayn22
on Programmers
See other posts from Programmers
or by nischayn22
Published on 2012-06-14T17:02:07Z
Indexed on
2012/06/16
9:22 UTC
Read the original article
Hit count: 212
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
© Programmers or respective owner