M
M
Max Ba2018-02-21 13:22:13
PHP
Max Ba, 2018-02-21 13:22:13

Do I need to declare the db property in the class?

There is a database class. Static singleton.
Is it necessary to create a db protected property when creating new classes and work with db-> inside the class, and not in DB::
If so, what is the fundamental difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-02-21
@qonand

There is a database class. Static singleton.

Singleton is not very good ... why - you can just google it, quite a few materials are devoted to this
Well, it all depends on how you will transfer the database object to a specific instance. If, for example, you use some kind of dependency injection, then by itself you need to write the base object into a class property. If you plan to do something like this $this->db = DB::getInstance() in classes, then this will give a special profit (except for a slight increase in code readability), but it will increase the amount of memory used (by allocating additional references to database object)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question