example:<?php
class Example{
static $num=0;
function __construct(){
}
}
class Children extends Example{
function __construct(){
self::$num+=1;
}
}
class Childrentwo extends Example{
function ob(){
echo self::$num;
}
}
$obj2=new Childrentwo();
echo 'result1:'.$obj2->ob();
//output: result1:0
$obj=new Children();
//echo $obj->$num,'<br/>';实例化->读取静态变量无效
echo "result2:".$obj::$num.'<br/>';
//output: result2:1
echo "result3:".Example::$num.'<br/>';
//output: result3:1
?>