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