<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title> Page Title </title>
<meta name= "keywords" content= "keyword list"/>
<meta name= "description" content= "Web description"/>
<link rel= "stylesheet" type= "text/css" href= "/>
<style type= "Text/css" ></style>
<script type= "Text/javascript" ></script>
<body>
<?php
Class a{
static $p 1 = 1;
static function Showinfo () {//inheritable
Self represents the current class: The class in which the code resides (static binding)
echo "<br/>". Self:: $p 1;
}
static function ShowInfo2 () {//inheritable
Static also represents the "current class": The class that calls this method
The word "static" sometimes represents the same class as self,
There are also times when a different class is represented: static represents the caller (dynamic binding)
It is generally thought that this situation is more in line with the needs of reality
It can be seen that the self is completely replaced by static.
echo "<br/>".Static:: $p 1;
}
}
Class B extends a{
static $p 1 = 10;//Property Overrides
}
A::showinfo ();//No doubt: 1
B::showinfo ();/??? The result is 1.
Because self always represents the class of the code in which it resides
echo "A::showinfo2 ();//The result is 1.
B::showinfo2 ();//The result is 10.
?>
</body>
Results in the Web page output:
1
1
1
10
The difference between self and static in PHP