Sharing objects between PHP classes

前端 未结 5 1735
予麋鹿
予麋鹿 2020-12-21 04:17

What is the best way to share objects between other classes?

For example; a \"database\" object with functions that are required by the \"article\" and \"user\" obje

5条回答
  •  爱一瞬间的悲伤
    2020-12-21 04:54

    Yes, that's pretty much the way you want to do. If a class has external requirements, don't create them inside the class, but require them as arguments in the constructor.

提交回复
热议问题