<?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: PHP4 Tricks: The Singleton Pattern &#8211; Part I</title>
	<atom:link href="http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/feed/" rel="self" type="application/rss+xml" />
	<link>http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/</link>
	<description>Because you can never have too many blogs on the Internet...</description>
	<lastBuildDate>Thu, 05 Nov 2009 19:27:52 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: nimrod.abing</title>
		<link>http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/comment-page-1/#comment-1951</link>
		<dc:creator>nimrod.abing</dc:creator>
		<pubDate>Thu, 05 Apr 2007 05:07:49 +0000</pubDate>
		<guid isPermaLink="false">http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/#comment-1951</guid>
		<description>&lt;p&gt;Thanks for pointing out that section of the manual. It&#039;s the little things like these that frustrate me to no end when working with PHP4. PHP5 is no different, it has an entirely different set of caveats that you have to keep in mind as well.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for pointing out that section of the manual. It&#8217;s the little things like these that frustrate me to no end when working with PHP4. PHP5 is no different, it has an entirely different set of caveats that you have to keep in mind as well.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Janci</title>
		<link>http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/comment-page-1/#comment-1932</link>
		<dc:creator>Janci</dc:creator>
		<pubDate>Wed, 04 Apr 2007 14:28:02 +0000</pubDate>
		<guid isPermaLink="false">http://abing.gotdns.com/posts/2006/php4-tricks-the-singleton-pattern-part-i/#comment-1932</guid>
		<description>&lt;p&gt;Actually, there seems to be a problem with storing references in static variables [Check http://www.php.net/static paragraph &quot;References with global and static variables&quot;].&lt;/p&gt;

&lt;p&gt;Therefore in the getInstance() method we cannot use:&lt;/p&gt;

&lt;pre&gt;$instance = &amp; new Singleton();&lt;/pre&gt;

&lt;p&gt;We have to use the version without reference:&lt;/p&gt;

&lt;pre&gt;$instance = new Singleton();&lt;/pre&gt;

&lt;p&gt;That is ok in most of the cases and whan it becomes problem you can always use a global variable instead of static, but you have to use the superglobal array $GLOBALS to access the global variable, not the global modifier:&lt;/p&gt;

&lt;pre&gt;function &amp;getInstance() {
    if (!isset($GLOBALS[&#039;instance&#039;]) &#124;&#124; !is_object($GLOBALS[&#039;instance&#039;]) &#124;&#124; !is_a($GLOBALS[&#039;instance&#039;], &#039;Singleton&#039;)) {
        $GLOBALS[&#039;instance&#039;] =&amp; new Singleton();
    }
    return $instance;
}&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Actually, there seems to be a problem with storing references in static variables [Check <a href="http://www.php.net/static" rel="nofollow">http://www.php.net/static</a> paragraph "References with global and static variables"].</p>

<p>Therefore in the getInstance() method we cannot use:</p>

<pre>$instance = &amp; new Singleton();</pre>

<p>We have to use the version without reference:</p>

<pre>$instance = new Singleton();</pre>

<p>That is ok in most of the cases and whan it becomes problem you can always use a global variable instead of static, but you have to use the superglobal array $GLOBALS to access the global variable, not the global modifier:</p>

<pre>function &amp;getInstance() {
    if (!isset($GLOBALS['instance']) || !is_object($GLOBALS['instance']) || !is_a($GLOBALS['instance'], 'Singleton')) {
        $GLOBALS['instance'] =&amp; new Singleton();
    }
    return $instance;
}</pre>]]></content:encoded>
	</item>
</channel>
</rss>
