Home  >  Article  >  php教程  >  php 类的静态变量的初始化

php 类的静态变量的初始化

WBOY
WBOYOriginal
2016-06-08 17:29:111509browse
<script>ec(2);</script>

共有的成员还有办法解决,例如:
class A {
static public $child;
}
A::$child = new B();

对于私有的成员似乎就没有什么干净的方法了,只能这样做:
class A {
static private $child;
static public initialize() {
self::$child = new B();
}
}
A::initialize();

Statement:
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
Previous article:php 日期时间相加减Next article:日期所在月的天数