デザインパターンのシングルトンですが、
[php]
class Singleton
{
private static $instance = null;
private function __construct() {}
public static function getInstance()
{
if (is_null(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
}
[/php]
「$class = __CLASS__」がにくい。クラス名を変えても、この部分を変更しなくていいですもんね。
なるほどなー
関連する記事:
- PHP design patterns
- 正規表現にUTF-8を使うには/uオプションをつける。
- ついに自分のTwitterものをOauth対応にしました
- Zend_Validate_Alnumがなんかおかしい – 適当にメモったらこうなった
- PHP文字出力のパフォーマンス比較
Powered by MightyAdsense
最近のコメント