Copy Code code as follows:
<?php
/**********************************************
* __construct Object initialization function uses
* Use of destruct destructors
* $this use of keywords ($this keywords are system variables 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 object, enclose initialization value in parentheses
$this->name= $name;
$this->type= $type;
}
Function VOD () {
Return $this->name. $this->type. ' Play a movie ';
}
function Game () {
Return $this->name. $this->type. ' Play the game ';
}
/************************
* When the internal operation of the object is completed,
* __DESTRUCT () is called,
* Then the memory used by the object is released. Rule: Backward First out
**************************/
function __destruct () {
echo "<br>==============". $this->name;
}
}
$PC 1 = new MyPC (' home computer ', ' Desktop ');
echo $pc 1->vod (). <br> ";
When the $pc1=null is completed, the object is released directly after the current instance operation completes
$pic 2 = new MyPC (' Company computer ', ' notebook ');
echo $pic 2->game ();