PHPでのシングルトンパターン
まあ自分の場合はこう書くかなあ
<?php class Klass { private function __construct() { } static function getInstance() { static $obj = null; return $obj ? $obj : $obj = new self; // 5.3以降なら return $obj ?: $obj = new self; } } Klass::getInstance();
まあ自分の場合はこう書くかなあ
<?php class Klass { private function __construct() { } static function getInstance() { static $obj = null; return $obj ? $obj : $obj = new self; // 5.3以降なら return $obj ?: $obj = new self; } } Klass::getInstance();