<?php
class Dad
{
public static function whoAmI()
{
return 'I am '.__CLASS__;
}
public static function testSelf()
{
echo 'self: '.self::whoAmI().'<br>';
}
public static function testStatic()
{
echo 'static: '.static::whoAmI().'<br>';
}
}
class Son1 extends Dad
{
public static function whoAmI()
{
return 'rewrite: I am '.__CLASS__;
}
}
class Son2 extends Dad
{
//重写父类的方法
//调用testStatic()将调子类重写后的方法
//调用testSelf()将依旧调用父类的whoAmI()
public static function whoAmI()
{
return 'rewrite: I am '.__CLASS__;
}
}
Son1::testSelf();//echo self: I am Dad
Son1::testStatic();//echo static: I am Son1
echo '<hr>';
Son2::testSelf();//echo self: I am Dad
Son2::testStatic();//echo static: I am Son2