class Main {
static $service;
public function __construct() {
$this->getService ()->t ();
$this->getService ()->t ();
}
public static function getService1() {
return new Service ( "BB" );
}
public static function getService2() {
if (self::$service == null) {
self::$service = new Service ();
}
return self::$service;
}
public function getService3() {
return self::$service = new Service ( "BB" );
}
}
//请问service类初始化了几次 那种getservice写法合格
new Main ();
那种写法合格?
探讨PHP 静态变量 静态方法 初始化类的问题 哪种写法合格,布布扣,bubuko.com
探讨PHP 静态变量 静态方法 初始化类的问题 哪种写法合格
原文地址:http://my.oschina.net/u/554046/blog/302037