You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
751 B
40 lines
751 B
<?php
|
|
//静态绑定前
|
|
class ClassA{
|
|
public function fnA(){
|
|
echo __CLASS__.PHP_EOL;
|
|
}
|
|
|
|
public function fnB(){
|
|
self::fnA(); //调用的是ClassA中的fnA
|
|
}
|
|
}
|
|
|
|
class ClassB extends ClassA
|
|
{
|
|
public function fnA(){
|
|
echo __CLASS__.PHP_EOL;
|
|
}
|
|
}
|
|
|
|
ClassB::fnB();
|
|
|
|
//后期静态绑定
|
|
class ClassC{
|
|
public function fnA(){
|
|
echo __CLASS__.PHP_EOL;
|
|
}
|
|
|
|
public function fnB(){
|
|
static::fnA(); //继承之后static代表的是ClassB
|
|
}
|
|
}
|
|
|
|
class ClassD extends ClassC{
|
|
public function fnA(){
|
|
echo __CLASS__.PHP_EOL;
|
|
}
|
|
}
|
|
|
|
ClassD::fnB();
|
|
?>
|