<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: PHP 5 Design Pattern : Singleton</title>
	<atom:link href="http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/</link>
	<description>Making a better life for web developer since 2006</description>
	<lastBuildDate>Mon, 08 Mar 2010 12:51:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adam</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-887</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Wed, 09 Jan 2008 14:23:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-887</guid>
		<description>Don&#039;t you just &lt;strong&gt;love&lt;/strong&gt; singletons!</description>
		<content:encoded><![CDATA[<p>Don&#8217;t you just <strong>love</strong> singletons!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Barta</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-244</link>
		<dc:creator>Tom Barta</dc:creator>
		<pubDate>Thu, 29 Nov 2007 04:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-244</guid>
		<description>I agree with other methods than an explicit singleton is overkill - design patterns used for the sake of themselves are worthless.  The important question is &quot;what problem am I trying to solve?&quot;  If all you want is a single entrypoint to access the database, this would be more straightforward (sorry if formating doesn&#039;t work well):

class MysqlDB {

  // complete class definition to connect to a mysql db

}

function getSiteDB() {

    static $db = new MysqlDB(USER, PASS, HOST, ...);

    return $db;

}

getSiteDB()-&gt;query(...);

getSiteDB()-&gt;query(...);

Why is this better?  Because this increases the usability of the database object.  If a single script needs to connect to 5 different databases, it&#039;s now possible without having to mess with singletons.  Plus, now the database class definition is reusable across different projects (anytime you need a MySQL database connection), because the specifics of the particular site are layered on top of the MysqlDB object, instead of embedded into it.</description>
		<content:encoded><![CDATA[<p>I agree with other methods than an explicit singleton is overkill &#8211; design patterns used for the sake of themselves are worthless.  The important question is &#8220;what problem am I trying to solve?&#8221;  If all you want is a single entrypoint to access the database, this would be more straightforward (sorry if formating doesn&#8217;t work well):</p>
<p>class MysqlDB {</p>
<p>  // complete class definition to connect to a mysql db</p>
<p>}</p>
<p>function getSiteDB() {</p>
<p>    static $db = new MysqlDB(USER, PASS, HOST, &#8230;);</p>
<p>    return $db;</p>
<p>}</p>
<p>getSiteDB()-&gt;query(&#8230;);</p>
<p>getSiteDB()-&gt;query(&#8230;);</p>
<p>Why is this better?  Because this increases the usability of the database object.  If a single script needs to connect to 5 different databases, it&#8217;s now possible without having to mess with singletons.  Plus, now the database class definition is reusable across different projects (anytime you need a MySQL database connection), because the specifics of the particular site are layered on top of the MysqlDB object, instead of embedded into it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sach</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-241</link>
		<dc:creator>sach</dc:creator>
		<pubDate>Tue, 27 Nov 2007 16:47:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-241</guid>
		<description>et pourquoi pas faire juste une fonction globale ?


(je sors)</description>
		<content:encoded><![CDATA[<p>et pourquoi pas faire juste une fonction globale ?</p>
<p>(je sors)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bungle</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-225</link>
		<dc:creator>bungle</dc:creator>
		<pubDate>Fri, 23 Nov 2007 17:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-225</guid>
		<description>&quot;Also note, that there’s a significant difference between singletons in PHP and other languages.&quot;

And that&#039;s what makes them unneeded for PHP. PHP scripts should be straightforward and to the point (and they share nothing). These singleton abstraction layers only complicate PHP processing for no added benefits.</description>
		<content:encoded><![CDATA[<p>&#8220;Also note, that there’s a significant difference between singletons in PHP and other languages.&#8221;</p>
<p>And that&#8217;s what makes them unneeded for PHP. PHP scripts should be straightforward and to the point (and they share nothing). These singleton abstraction layers only complicate PHP processing for no added benefits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHP 5: MySQL Singleton Example &#124; eKini Web Development Blog</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-223</link>
		<dc:creator>PHP 5: MySQL Singleton Example &#124; eKini Web Development Blog</dc:creator>
		<pubDate>Fri, 23 Nov 2007 03:32:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-223</guid>
		<description>[...] Here is a good example of using a Singleton. [...]</description>
		<content:encoded><![CDATA[<p>[...] Here is a good example of using a Singleton. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivo Jansch</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-222</link>
		<dc:creator>Ivo Jansch</dc:creator>
		<pubDate>Thu, 22 Nov 2007 21:11:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-222</guid>
		<description>Also note, that there&#039;s a significant difference between singletons in PHP and other languages. In most languages, Singletons follow your definition &#039;one instance across the system&#039;. In PHP, the singleton that you are creating is &#039;one instance per request&#039;. Usually this is ok, but if you&#039;re coming from other languages and used to using Singletons in their pure form, it might be confusing.</description>
		<content:encoded><![CDATA[<p>Also note, that there&#8217;s a significant difference between singletons in PHP and other languages. In most languages, Singletons follow your definition &#8216;one instance across the system&#8217;. In PHP, the singleton that you are creating is &#8216;one instance per request&#8217;. Usually this is ok, but if you&#8217;re coming from other languages and used to using Singletons in their pure form, it might be confusing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaGalaxy.com</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-219</link>
		<dc:creator>JavaGalaxy.com</dc:creator>
		<pubDate>Thu, 22 Nov 2007 17:10:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-219</guid>
		<description>A little more explanation on using this patten in a real time application would be helpful.</description>
		<content:encoded><![CDATA[<p>A little more explanation on using this patten in a real time application would be helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FlorentG</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-217</link>
		<dc:creator>FlorentG</dc:creator>
		<pubDate>Thu, 22 Nov 2007 15:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-217</guid>
		<description>Remember to read &quot;Singletons Are Evil&quot; ( http://c2.com/cgi/wiki?SingletonsAreEvil ). Lots of people uses Singleton only to replace globals variables, because it makes them feel they&#039;re not using globals anymore.</description>
		<content:encoded><![CDATA[<p>Remember to read &#8220;Singletons Are Evil&#8221; ( <a href="http://c2.com/cgi/wiki?SingletonsAreEvil" rel="nofollow">http://c2.com/cgi/wiki?SingletonsAreEvil</a> ). Lots of people uses Singleton only to replace globals variables, because it makes them feel they&#8217;re not using globals anymore.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antoine Ughetto</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-215</link>
		<dc:creator>Antoine Ughetto</dc:creator>
		<pubDate>Thu, 22 Nov 2007 15:44:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-215</guid>
		<description>We have just make some upgrades with syntax highlighting. Hope it will be easy to read</description>
		<content:encoded><![CDATA[<p>We have just make some upgrades with syntax highlighting. Hope it will be easy to read</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: butters</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-214</link>
		<dc:creator>butters</dc:creator>
		<pubDate>Thu, 22 Nov 2007 15:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-214</guid>
		<description>Nice post, but i find its hard to read. Not because of the content, but the design makes it extremly difficult...</description>
		<content:encoded><![CDATA[<p>Nice post, but i find its hard to read. Not because of the content, but the design makes it extremly difficult&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHPDeveloper.org</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-213</link>
		<dc:creator>PHPDeveloper.org</dc:creator>
		<pubDate>Thu, 22 Nov 2007 13:10:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-213</guid>
		<description>&lt;strong&gt;Make Me Pulse Blog: PHP 5 Design Pattern : Singleton...&lt;/strong&gt;


On the Make Me Pulse blog today, Antoine Ughetto takes a ......</description>
		<content:encoded><![CDATA[<p><strong>Make Me Pulse Blog: PHP 5 Design Pattern : Singleton&#8230;</strong></p>
<p>On the Make Me Pulse blog today, Antoine Ughetto takes a &#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dougal</title>
		<link>http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/comment-page-1/#comment-212</link>
		<dc:creator>Dougal</dc:creator>
		<pubDate>Thu, 22 Nov 2007 12:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.makemepulse.com/2007/11/22/php-5-design-pattern-singleton/#comment-212</guid>
		<description>Duude... get some syntax highlighting :)

I like to write it like this, so its easier to copy accross classes etc.

	public static function getInstance(){
	
		if (self::$instance === null) {
			
			$x = __CLASS__;
			self::$instance = new $x;
			
		}
		
		return self::$instance;
		
	}</description>
		<content:encoded><![CDATA[<p>Duude&#8230; get some syntax highlighting <img src='http://blog.makemepulse.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I like to write it like this, so its easier to copy accross classes etc.</p>
<p>	public static function getInstance(){</p>
<p>		if (self::$instance === null) {</p>
<p>			$x = __CLASS__;<br />
			self::$instance = new $x;</p>
<p>		}</p>
<p>		return self::$instance;</p>
<p>	}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
