时间:2021-07-01 10:21:17 帮助过:20人阅读
class A { public $f1 = 'xxxx'; static public $f2 = 100; } |
如果要将变量赋值为对象,那么只能在构造器中进行初始化,例如:
class A { private $child; public function __construct() { $this->child = new B(); } } |
class A { static public $child; } A::$child = new B(); |
对于私有的成员似乎就没有什么干净的方法了,只能这样做:
class A { static private $child; static public initialize() { self::$child = new B(); } } A::initialize(); |
http://www.bkjia.com/PHPjc/364373.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364373.htmlTechArticlephp的成员变量可以在声明的同时进行初始化,但是只能用标量进行初始化,例如: class A { public $f1 = 'xxxx'; static public $f2 = 100; } 如果要将变...