PHP - a DB abstraction layer use static class vs singleton object?

后端 未结 5 897
小蘑菇
小蘑菇 2020-12-05 00:54

I don\'t want to create a discussion about singleton better than static or better than global, etc. I read dozens of questions about similar subjects on SO, but I couldn\'t

5条回答
  •  遥遥无期
    2020-12-05 01:21

    Making DB library static is certainly shorter and quicker, than doing:

    $db = DBSingleton::blabla(); // everytime I need ya

    But also, since it is global, tempting to use everywhere.

    So, choose other methods if you want clean code... and choose static if you need quick code ;-)

提交回复
热议问题