Benefits of using a constructor?

前端 未结 5 1527
眼角桃花
眼角桃花 2020-12-10 07:49

In my quest in trying to learn more about OOP in PHP. I have come across the constructor function a good few times and simply can\'t ignore it anymore. In my understanding,

5条回答
  •  一生所求
    2020-12-10 08:05

    The constructor allows you to ensure that the object is put in a particular state before you attempt to use it. For example, if your object has certain properties that are required for it to be used, you could initialize them in the constructor. Also, constructors allow a efficient way to initialize objects.

提交回复
热议问题