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

后端 未结 5 885
小蘑菇
小蘑菇 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:05

    My advice: STOP using Singleton and static all together.

    Why? Because you will insert dependencies that will render your code unusable in other projects, and will not allow to unit test it. Also forget about loose coupling if using singleton.

    The alternatives? Dependency Injection. http://www.potstuck.com/2009/01/08/php-dependency-injection

提交回复
热议问题