PHP的类与对象中文手册:Static(静态)关键字
2019-09-07 阅读 : 次
Tip
<?php
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 . "/n";
$foo = new Foo();
print $foo->staticValue() . "/n";
print $foo->my_static . "/n"; // Undefined "Property" my_static
print $foo::$my_static . "/n";
$classname = 'Foo';
print $classname::$my_static . "/n"; // As of PHP 5.3.0
print Bar::$my_static . "/n";
$bar = new Bar();
print $bar->fooStatic() . "/n";
?>
</programlisting>
</example>
<example>
<title>静态方法示例</title>
<programlisting role="php">
<
