Home > php教程 > PHP源码 > php Static关键字静态变量的实用方法(1/3)

php Static关键字静态变量的实用方法(1/3)

WBOY
Release: 2016-06-08 17:26:55
Original
1097 people have browsed it
<script>ec(2);</script>
 代码如下 复制代码
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() . " ";
?>

 

首页 1 2 3 末页
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template