Purpose of PHP constructors

后端 未结 6 1715
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 20:14

I am working with classes and object class structure, but not at a complex level – just classes and functions, then, in one place, instantiation.

As to __const

6条回答
  •  一个人的身影
    2020-11-30 20:25

    I've found it was easiest to grasp when I thought about the new keyword before the constructor: it simply tells my variable a new object of its data type would be give to him, based on which constructor I call and what I pass into it, I can define to state of the object on arrival.

    Without the new object, we would be living in the land of null, and crashes!

    The Destructor is most obvious from a C++ stand point, where if you dont have a destructor method delete all the memory pointed to, it will stay used after the program exits causing leaks and lag on the clients OS untill next reboot.

    I'm sure there's more than enough good information here, but another angle is always helpful from what I've noticed!

提交回复
热议问题