//static关键字
class A
{
public static $aa = 'A::$aa';
public function static_aa() {
return self::$aa;
}
}
class B extends A
{
public function static_bb() {
return parent::$aa;//调用基类中的公有static属性
}
//定义静态方法
public static function b_mystatic()
{
echo "我是B的静态方法";
}
}
print A::$aa. "\n";//公有可以访问
$a1 = new A();
print $a1->static_aa() . "\n";
//print $a1->aa. "\n"; // 未定义的属性 aa
print B::$aa . "\n";//继承自A
$b1 = new B();
print $b1->static_bb() . "\n";
B::b_mystatic();
?>
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/106371,如需转载请自行联系原作者