标签:
<?php
class MyObject {
public static $myStaticVar = 0;
function myMethod() {
self::$myStaticVar += 2;
echo self::$myStaticVar."\n";
}
}
class MyOtherObject extends MyObject {
public static $myStaticVar = 0; //重写了myStaticVar
function myOtherMethod() {
echo parent::$myStaticVar."\n";
echo self::$myStaticVar."\n";
}
}
$instance1 = new MyObject();
$instance1->myMethod();
$instance2 = new MyObject();
$instance2->myMethod();
$instance3 = new MyOtherObject();
$instance3->myOtherMethod();
//2
//4
//4
//0
rewrite_static
标签:
原文地址:http://www.cnblogs.com/yhdsir/p/4649131.html