<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Calhoun&#039;s Blog &#187; singleton</title>
	<atom:link href="http://davidbcalhoun.com/tag/singleton/feed" rel="self" type="application/rss+xml" />
	<link>http://davidbcalhoun.com</link>
	<description>Just another blog</description>
	<lastBuildDate>Mon, 07 May 2012 02:06:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>PHP Tidbit: Dead simple singleton</title>
		<link>http://davidbcalhoun.com/2009/php-tidbit-dead-simple-singleton</link>
		<comments>http://davidbcalhoun.com/2009/php-tidbit-dead-simple-singleton#comments</comments>
		<pubDate>Tue, 15 Sep 2009 05:50:45 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=15</guid>
		<description><![CDATA[class Singleton { private static $instance; public static function getInstance() { if(!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; } } And the explanation&#8230; class Singleton { private static $instance; // static variable to hold our 1 instance public static function getInstance() { // function to get the 1 instance if(!isset(self::$instance)) [...]]]></description>
			<content:encoded><![CDATA[<pre name="code" class="php">class Singleton {
    private static $instance;
    public static function getInstance() {
        if(!isset(self::$instance)) {
            $c = __CLASS__;
            self::$instance = new $c();
        }
        return self::$instance;
    }
}</pre>
<p>And the explanation&#8230;</p>
<pre name="code" class="php">class Singleton {
    private static $instance;               // static variable to hold our 1 instance

    public static function getInstance() {  // function to get the 1 instance
        if(!isset(self::$instance)) {       // this will only run once (and instantiate once)
            $c = __CLASS__;                 // get the class (Singleton)
            self::$instance = new $c();     // instantiate the class and store it in our variable
        }
        return self::$instance;             // return the instance
    }

    public static function myFunction() {   // we can get to this through Singleton::getInstance()->myFunction()
        // ...
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/php-tidbit-dead-simple-singleton/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

