Answer the question
In order to leave comments, you need to log in
Database Singleton or Dependency Injection?
Actually, which is better to use? Both options work, but which one is better? Thanks in advance.
PS There is a Database class (select, update, etc.). And there is a User class that uses methods from the Database class.
Answer the question
In order to leave comments, you need to log in
ST is generally recognized as an anti-pattern in PHP, firstly we do not test it, and secondly it is static.
In the case of a database, it will also not allow you to connect to more than 1 database / storage.
If religion does not allow DI, use registry, this is also badly tested, but in any case there will be no static database object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question