A simple example of php initialization objects and Destructor. Copy the code as follows :? Php *************************************** * ******* _ use of the * destruct destructor ** $ this keyword for the construct object initialization function (
The code is as follows:
/*************************************** *******
* _ Construct object initialization function usage
* Use of destruct destructor
* $ This keyword is used to access the object attributes and system variables of the object * method in the current object)
*
**************************************** ******/
Header ("Content-Type: text/html; charset = UTF-8 ");
Class mypc {
Public $ name;
Public $ type;
Function _ construct ($ name = '', $ type ='') {// initialize the object and put the initialization value in brackets
$ This-> name = $ name;
$ This-> type = $ type;
}
Function vod (){
Return $ this-> name. $ this-> type. 'play ';
}
Function game (){
Return $ this-> name. $ this-> type. 'player ';
}
/************************
* When the operation inside the object is completed,
* _ Destruct () is called,
* The memory used by the object is then released. Rule: Forward, forward, and forward
**************************/
Function _ destruct (){
Echo"
================ ". $ This-> name;
}
}
$ Pc1 = new mypc ('Home PC', 'desktop ');
Echo $ pc1-> vod ()."
";
// When $ pc1 = null, the object is directly released after the current instance operation is complete.
$ Pic2 = new mypc ('Company ID', 'laptop ');
Echo $ pic2-> game ();
The http://www.bkjia.com/PHPjc/740210.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/740210.htmlTechArticle code is as follows :? Php /************************************** * ******** _ use of the * destruct destructor * $ this keyword to initialize the function of a construct object (...