請看下面的程式碼:
複製程式碼 程式碼如下:
class A {
public function x() {
echo "A::x() was called.n";
}
public function y() {
self::x();
echo "A::y() was called.n";
}
public function z() {
$this->x();
echo "A::z() was called .n";
}
}
class B extends A {
public function x() {
echo "B::x() was called.n";
}
}
$b = new B();
$b->y();
echo "--n";
$b->z();
?>
複製程式碼 程式碼如下:
Parent says $str Child says $ str AnotherChild says $str
static::do_print( $str );
}
static public function do_print( $str ) {
echo "
}
}
class ChildClass extends ParentClass {
static public function do_print( $str ) {
echo "
}
}
class AnotherChildClass extends ParentClass {
static public function do_print( $str ) {
echo "
}
}
echo phpversion();
$a=new ChildClass();
$a->say( 'Hello' );
$b= new AnotherChildClass();
$b->say( 'Hello' );
以上就介紹了h5 PHP5中虛函數的實作方法分享,包含了h5方面的內容,希望對PHP教學有興趣的朋友有幫助。