PHP Abstract Interface-destructor method

Source: Internet
Author: User

/*class Ren
{
public static $color;
static function Show ()
{
Ren:: $color;//Use the class name not only to call your own, but also to call other classes of car:: $name
Self:: $color;//You can only call this class with self
}
}
Class Car
{
public static $name;
}*/
Abstract class Keywords
/*abstract class Dongwu
{
Public $dong;
Public $jiao;
function Chi ()
{
}
function Shui ()
{
}
}*/
Interfaces: Extremely abstract classes inherit from interfaces that must implement methods in the interface, overriding
Interface keyword Interface interface inside the method does not have a function body implementation of the interface using the keyword implement, without extends implementation of the interface subclasses must implement each method of the interface
/*interface dongwu//Use the interface keyword to not add class
{}
Class Ren extends Dongwu
{
}
$r =new Ren ();
Var_dump ($R); * *
$d =new Dongwu ();
/*interface USB
{
function Read ();
function Write ();
}
Mouse
Class Mouse implements USB
{
function Read ()
{
echo "Insert Mouse";
}
function Write ()
{
echo "Powered mouse";
}
}
Keyboard
Class Jianpan implements USB
{
function Read ()
{
echo "Insert Keyboard";
}
function Write ()
{
echo "Power-on keyboard";
}
}
$m =new Mouse ();
$m->read ();
$m->write (); */
Class Ren
{
Public $name = "Zhang San";
Public $sex;
Public $age;
function Run ()
{
}
Function Show ()
{
echo "name represents name, sex represents gender";
}
destructor key __destruct the memory is freed before the object is destroyed, the connection is closed, etc.
function __destruct ()
{
echo "destroyed";
}
Called when the object is output, there must be a return value
function __tostring ()
{
Return "name represents name, sex represents gender"
return $this->name;
}
}
Special __destruct
Execution time is special when object is destroyed
/* $r =new Ren ();
$r->name= "Zhang San";
Var_dump ($R); * *
$r =new Ren ();
$r->show ();
echo $r;//Direct Output Object __tostring () the method of turning an object into a string
Small knowledge points
$a = 10;
$b = 20;
$c = 25;
Unset ($b);
/*if (Isset ($b))
{
$sum = $a + $b;
Echo $sum;
echo "<br>";
Echo $a * $sum;
}*/
if (!isset ($b))
{
/*echo "Variable B does not exist";
Exit ();//Quit program */
Die ("Variable B does not exist");//Output error message and exit program
}
$sum = $a + $b;
Echo $sum;
echo "<br>";
Echo $a * $sum;
$attr =array (1,2,3,4);
$a = "Hello";
Var_dump ($attr);//Data and type
Print_r ($attr);//Data
echo "HHH", "hh";//can output multiple strings in the middle with commas
print "RR"; Only one string can be output

PHP Abstract Interface-destructor method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.