代码如下 | 复制代码 |
class Foo { public static $my_static = 'foo'; public function staticValue() { return self::$my_static; } } class Bar extends Foo { public function fooStatic() { return parent::$my_static; } } print Foo::$my_static . " "; $foo = new Foo(); print $foo->staticValue() . " "; print $foo->my_static . " "; // Undefined "Property" my_static print $foo::$my_static . " "; $classname = 'Foo'; print $classname::$my_static . " "; // PHP 5.3.0之后可以动态调用 print Bar::$my_static . " "; $bar = new Bar(); print $bar->fooStatic() . " "; ?> |