Php constructor and Destructor
In php programming, an object-oriented function is called a constructor. it is a method automatically called when an object is created to complete class initialization.
As long as the php class is loaded, this function is automatically executed, and initialization is generally stored in this function. 1. Like other functions, constructor can pass parameters and set the default values of parameters.
2. constructor can call attributes and call methods. 3. constructors can be explicitly called by other methods.
In the previous php version, the constructor uses the same name as the class name to initialize the object. However, if you want to change the class name, you must change its constructor, therefore, php5 is implemented using the _ construct () function. _ construct () consists of two underscores. The Destructor corresponds to the constructor. it is executed when an object becomes junk or when the object is explicitly destroyed.
The _ destruct () destructor is executed when the garbage object is recycled. 1. do not call the destructor of an object in a program. 2. the destructor cannot contain parameters. 3. php automatically executes garbage collection after the program ends. Because sometimes multiple instances are created for a class, how does the constructor call it. Php constructor calls the most recent php constructor from its own lookup and execution. |