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