/*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