Copy code The code is as follows:
/**************************************************
* __construct object Use of initialization function
* destruct Use of destructor
* Use of $this keyword ($this keyword is a system variable used to access object properties and object * methods 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, put the initialization value in brackets
$this->name=$name;
$this->type=$type;
}
function vod(){
return $this->name.$this->type.'Play movie';
}
function game(){
return $this->name.$this->type.'Play games';
}
/************************
* When the operation inside the object is completed,
* __destruct() is called,
* Then the memory used by the object is released. Rules: Last in, first out
*******************************/
function __destruct(){
echo "
name;
}
}
$pc1 = new mypc('Home Computer',' Desktop');
echo $pc1->vod()."
";
//When $pc1=null;, the object is released directly after the current instance operation is completed
$pic2 = new mypc('company computer','notebook');
echo $pic2->game();
http://www.bkjia.com/PHPjc/740210.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/740210.htmlTechArticleCopy the code as follows: ?php /**************** ****************************** * The use of __construct object initialization function * The use of destruct destructor * The use of $this keyword (...