html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
多态class xs {
public function show($g){
$g->display();
}
}
class dd {
public function display(){
echo "red show";
}
}
class ff{
public function display(){
echo "blue show";
}
}
//多态的使用
$a=new dd();
$b=new ff();
$red=new xs();
$red->show($a);
$red->show($b);
?>
html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
静态属性和静态方法 static/**
* 注意静态方法存放在类当中,因此无需
*类在内存中只有一个,静态属性只有一个
*/
class Human
{
public static $a=1;
public function chang()
{
return Human::$a=9;
}
}
echo Human::$a.'
';
$a=new Human();
$b=new Human();
echo $a->chang().'
';
echo $b->chang().'
';
/**
*普通方法需要绑定$this,而静态方法不需要this
*不用声明对象,可以直接调用静态方法
*
***/
class People
{
static public function cry()
{
echo "5555";
}
}
People::cry();
?>
html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
静态属性和静态方法 static/**
*总结方法用self::$a 和parent::$b来表示子类和父类
*
***/
class People
{
static public $m=1;
}
class P extends People{
static public $n=2;
public function getA(){
echo self::$n;
}
public function getB(){
echo parent::$m;
}
}
$w=new P();
$w->getA();
$w->getB();
?>